public MultipleCell(Cell c, List<Cell> cells ) : base(c, true) { _CellOptions = new List<Cell>(); _OptionNames = new List<string>(); AddCellToOptions(c, cells, true); _baseName = c.Label.Substring(0, c.Label.IndexOf('[')); _CellType = CellType.Multiple; // set selected cell to first option in list of cells _SelectedCell = _CellOptions[0]; }
public void AddCellToOptions(Cell c, List<Cell> cells, bool newMultiCellRow) { var kCell = c as KCell; var cCell = c as CCell; var mCell = c as MCell; var wCell = c as WCell; if (kCell != null) { KCell kc = new KCell(kCell, newMultiCellRow); AddOptionCell(kc); } else if (cCell != null) { List<string> names = cCell.ConnectionInfo.Split(new char[] { '(', ')', '+', '-', '*', '/', '^' }).ToList(); // need for TryParse double n; List<string> dependencyNamesPossibleDupes = (from name in names where name.Length > 0 && !double.TryParse(name, out n) // make sure the value isn't a direct value select name).ToList(); List<string> dependencyNames = dependencyNamesPossibleDupes.Distinct().ToList(); List<Cell> dependencies = new List<Cell>(); foreach (string name in dependencyNames) { Cell dependency = cells.First(x => x.Label == name); if (dependency != null) dependencies.Add(dependency); } CCell cc = new CCell(cCell, dependencies, newMultiCellRow); AddOptionCell(cc); } else if (mCell != null) { MCell mc = new MCell(mCell, newMultiCellRow); AddOptionCell(mc); } else if (wCell != null) { WCell wc = new WCell(wCell, newMultiCellRow); AddOptionCell(wc); } }
public MultipleCell(MultipleCell multiple, List<Cell> cells) : base(multiple, false) { _CellOptions = new List<Cell>(); _OptionNames = new List<string>(); _baseName = multiple.BaseName; _CellType = CellType.Multiple; foreach (Cell c in multiple.CellOptions) { AddCellToOptions(c, cells, false); } // set selected cell to the first item in the list of cells _SelectedCell = _CellOptions[0]; }
private void WeightFindNextCell(Cell c, out int row, out int column) { // if there is no advance-to-element type go to next cell in line if (c.ConnectionInfo.ToLower() == "null") { BasicNextCell(c, out row, out column); return; } // otherwise find the cell to advance to // current row we're on List<Cell> cells = _Cells[c.RowIndex]; Cell nextCell = cells.First(x => String.Equals(x.Label, c.ConnectionInfo, StringComparison.CurrentCultureIgnoreCase)); // if nextCell isn't a weight cell, find the next weight cell on that line if (!(nextCell is WCell)) { // check if they keyboard cell is auto or ditto int index = cells.IndexOf(nextCell); while (index < cells.Count) { if (cells[index] is WCell) { nextCell = cells[index]; break; } // only go to KCell if the type is "null", meaning a comment if (cells[index] is KCell) { if (cells[index].ConnectionInfo.ToLower() == "null") { nextCell = cells[index]; break; } } index++; } } // go to next line if it is behind the current cell if (nextCell.ColumnIndex <= c.ColumnIndex) { row = c.RowIndex + 1; column = nextCell.ColumnIndex; } // otherwise move to the next cell accordingly else { row = nextCell.RowIndex; column = nextCell.ColumnIndex; } }
private void BasicNextCell(Cell c, out int row, out int column) { int columnCount = _Cells[0].Count; // left to right advance int nextCol = c.ColumnIndex + 1; if (nextCol < columnCount) { row = c.RowIndex; column = nextCol; } else { row = c.RowIndex + 1; column = 0; } }
public void NextCell(Cell c, out int row, out int column) { // get cell type int rowValue = -1, colValue = -1; switch (c.CellType) { // Calculation, Mirror Type, and Keyboard Cells will just progress to the next cell as normal case CellType.C: BasicNextCell(c, out rowValue, out colValue); break; case CellType.M: BasicNextCell(c, out rowValue, out colValue); break; case CellType.K: BasicNextCell(c, out rowValue, out colValue); break; case CellType.W: WeightFindNextCell(c, out rowValue, out colValue); break; case CellType.Multiple: BasicNextCell(c, out rowValue, out colValue); break; } row = rowValue; column = colValue; }
public void CheckAndUpdateMultipleDependency(Cell cell, MultipleCell mc) { int row = mc.RowIndex; List<CCell> calcCells = mc.CellOptions.OfType<CCell>().Select(c => c).ToList(); foreach (CCell cc in calcCells) { if (cc.IsDependency(cell)) { cc.Dependencies[cell] = cell.ValueChanged; cc.CheckDependencies(); } } }
public void CheckAndUpdateDependency(Cell cell) { int row = cell.RowIndex; List<Cell> rowValues = _Cells[row]; List<CCell> calcCells = (from calculation in rowValues where calculation is CCell select calculation as CCell).ToList(); foreach (CCell cc in calcCells) { // update dependency to make sure if value is changed // and has an actual value if (cc.IsDependency(cell)) { cc.Dependencies[cell] = cell.ValueChanged; cc.CheckDependencies(); } } // need to check multiple cells for dependencies as well List<MultipleCell> multiCells = (from multi in rowValues where multi is MultipleCell select multi as MultipleCell).ToList(); foreach (MultipleCell mc in multiCells) { foreach (Cell c in mc.CellOptions) { CCell calc = c as CCell; if (calc == null) continue; if (calc.IsDependency(cell)) { calc.Dependencies[cell] = cell.ValueChanged; calc.CheckDependencies(); } } } }
/// <summary> /// returns null if you don't need to add the cell to the columns /// </summary> /// <param name="c">Cell we're adding to Multiple Cell</param> /// <param name="cols">the current columns in the list</param> /// <returns></returns> private MultipleCell BuildMultipleCell(Cell c, List<Cell> cols ) { bool needToAddToCols = true; foreach (var cell in cols.OfType<MultipleCell>()) { if (cell.CanAddToOption(c.Label)) { // Cell already exists, don't need to make a new one with a new row (true) cell.AddCellToOptions(c, cols, true); needToAddToCols = false; break; } } if (needToAddToCols) { return new MultipleCell(c, cols); } return null; }
// copy constructor for next row public Cell(Cell c, bool multiCell = false) { Label = c.Label; Digits = c.Digits; Precision = c.Precision; ConnectionInfo = c.ConnectionInfo; if (multiCell) { RowIndex = c.RowIndex; } else { RowIndex = c.RowIndex + 1; } ColumnIndex = c.ColumnIndex; ValueChanged = false; }
public bool IsDependent(Cell c) { return c == _MirroredCell; }
public MCell(string label, int digits, int precision, string connectionInfo, int rowIndex, int columnIndex, Cell columnToMirror) : base(label, digits, precision, connectionInfo, rowIndex, columnIndex) { MirroredCell = columnToMirror; _CellType = CellType.M; }
/// <summary> /// figure out if cell is a dependency /// </summary> /// <param name="c"></param> /// <returns></returns> public bool IsDependency(Cell c) { return _Dependencies.ContainsKey(c); }
public void ChangeOption(string optName) { int indexOf = OptionStrings.IndexOf(optName); try { _SelectedCell = _CellOptions[indexOf]; NotifyHeaderNameChange(this, new EventArgs()); OnValueChanged(new PropertyChangedEventArgs("Value")); } catch (Exception) { // ignored } }
public void UpdateSelectedCell(int index) { try { _SelectedCell = _CellOptions[index]; } catch (Exception) { // ignored } }
private void AddOptionCell(Cell c) { var kCell = c as KCell; var mCell = c as MCell; var wCell = c as WCell; var cCell = c as CCell; if (kCell != null) _CellOptions.Add(kCell); else if (mCell != null) _CellOptions.Add(mCell); else if (wCell != null) _CellOptions.Add(wCell); else if (cCell != null) _CellOptions.Add(cCell); OptionStrings.Add(c.Label.Substring(c.Label.IndexOf('[') + 1, c.Label.IndexOf(']') - c.Label.IndexOf('[') - 1)); }