Beispiel #1
0
        public List<Cell> ReturnCellsInRow(int rowNumber)
        {
            List<Cell> cols = new List<Cell>();
            int colIndex = 0;

            foreach (List<string> l in _parsedFile)
            {
                MultipleCell multi = null;

                // there will be 5 items in each .APP file
                if (l.Count != 5) break;

                string label = l[0];
                string type = l[1];
                int digits;  // not really necessary for this application, but leaving for reverse compatibility
                int.TryParse(l[2], out digits);

                int precision;
                int.TryParse(l[3], out precision);
                string connectionInfo = l[4];

                switch (type)
                {
                    // keyboard cell
                    case "K":
                        if (MultipleCell.IsMultiCell(label) && cols.OfType<MultipleCell>().ToList().Count > 0) colIndex--;
                        KCell k = new KCell(label, digits, precision, connectionInfo, rowNumber, colIndex);
                        if (MultipleCell.IsMultiCell(label))
                        {
                            multi = BuildMultipleCell(k, cols);
                            if(multi != null) cols.Add(multi);
                        }
                        else
                        {
                            cols.Add(k);
                        }
                        break;
                    // weight cell
                    case "W":
                        if (MultipleCell.IsMultiCell(label) && cols.OfType<MultipleCell>().ToList().Count > 0) colIndex--;
                        WCell w = new WCell(label, digits, precision, connectionInfo, rowNumber, colIndex);

                        if (MultipleCell.IsMultiCell(label))
                        {
                            multi = BuildMultipleCell(w, cols);
                            if(multi != null) cols.Add(multi);
                        }
                        else
                        {
                            cols.Add(w);
                        }
                        break;
                    // calculation cell
                    case "C":
                        List<string> names =
                            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 an integer
                            select name).ToList();

                        List<string> dependencyNames = dependencyNamesPossibleDupes.Distinct().ToList();

                        List<Cell> dependencies = new List<Cell>();

                        foreach (string name in dependencyNames)
                        {
                            Cell dependency = cols.First(x => x.Label == name);

                            if(dependency != null)
                                dependencies.Add(dependency);
                        }

                        if (MultipleCell.IsMultiCell(label) && cols.OfType<MultipleCell>().ToList().Count > 0) colIndex--;

                        CCell c = new CCell(label, digits, precision, connectionInfo, rowNumber, colIndex,
                            dependencies);

                        if (MultipleCell.IsMultiCell(label))
                        {
                            multi = BuildMultipleCell(c, cols);
                            if(multi != null) cols.Add(multi);
                        }
                        else
                        {
                            cols.Add(c);
                        }

                        break;
                    // mirror cell
                    case "M":
                        // find cell to mirror
                        var columnToMirror = cols.FirstOrDefault(x => x.Label == connectionInfo);

                        if (MultipleCell.IsMultiCell(label) && cols.OfType<MultipleCell>().ToList().Count > 0) colIndex--;
                        MCell m = new MCell(label, digits, precision, connectionInfo, rowNumber, colIndex, columnToMirror);

                        if (MultipleCell.IsMultiCell(label))
                        {
                            multi = BuildMultipleCell(m, cols);
                            if(multi != null) cols.Add(multi);
                        }
                        else
                        {
                            cols.Add(m);
                        }
                        break;
                    // newscreen, for backwards compatibility
                    case "0":
                        NewScreen newScreen = new NewScreen(label, digits, precision, connectionInfo, rowNumber, colIndex);
                        cols.Add(newScreen);
                        break;

                }

                colIndex++;
            }

            return cols;
        }
Beispiel #2
0
 public NewScreen(NewScreen ns, bool multiCell = false) : base(ns, multiCell)
 {
     _CellType = CellType.NewScreen;
 }
Beispiel #3
0
 public NewScreen(NewScreen ns, bool multiCell = false) : base(ns, multiCell)
 {
     _CellType = CellType.NewScreen;
 }
Beispiel #4
0
        public void AddRow()
        {
            int nextRow = _Cells.Count;

            // check each cell

            List <Cell> cells = new List <Cell>();

            foreach (Cell c in _Cells[nextRow - 1])
            {
                if (c.CellType == CellType.C)
                {
                    CCell cc = c as CCell;

                    List <string> names = cc.ConnectionInfo.Split(new char[] { '(', ')', '+', '-', '*', '/', '^' }).ToList();

                    // need for TryParse
                    double n;

                    List <string> dependencyNamesPossibleDupes = new List <string>(); /* = (from name in names
                                                                                       * where name.Length > 0 &&
                                                                                       * !double.TryParse(name, out n)     // make sure the value isn't an integer
                                                                                       * select name).ToList(); */


                    foreach (string name in names)
                    {
                        if (name.Length > 0 && !double.TryParse(name, out n))
                        {
                            dependencyNamesPossibleDupes.Add(name);
                        }
                    }

                    // quicker way to get distinct values
                    HashSet <string> dependencyNames = new HashSet <string>(dependencyNamesPossibleDupes);

                    //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 copyWithCorrectRow = new CCell(cc, dependencies);
                    _CalculationCells.Add(copyWithCorrectRow);
                    cells.Add(copyWithCorrectRow);
                }
                else if (c.CellType == CellType.W)
                {
                    WCell wc = c as WCell;
                    cells.Add(new WCell(wc));
                }
                else if (c.CellType == CellType.K)
                {
                    KCell kc = c as KCell;

                    KCell kcToAdd = new KCell(kc);

                    if (kcToAdd.KConnectionType == KConnection.AUTO)
                    {
                        kcToAdd.Value = kc.Value + 1;
                    }
                    if (kcToAdd.KConnectionType == KConnection.DITTO)
                    {
                        kcToAdd.KValue = kc.KValue;
                    }
                    cells.Add(kcToAdd);
                }
                else if (c.CellType == CellType.M)
                {
                    MCell mc = c as MCell;
                    cells.Add(new MCell(mc));
                }
                else if (c.CellType == CellType.Multiple)
                {
                    MultipleCell multiple = c as MultipleCell;
                    cells.Add(new MultipleCell(multiple, cells));
                }
                else if (c.CellType == CellType.NewScreen)
                {
                    NewScreen ns = c as NewScreen;
                    cells.Add(new NewScreen(ns));
                }
            }
            _Cells.Add(cells);
        }