Example #1
0
        private string[][] EvaluateRules(BaseScore score, string[][] labels)
        {
            GenericScore genScore = score as GenericScore;

            if (genScore == null)
            {
                return(null);
            }

            RuleEvaluator engine = new RuleEvaluator(genScore.Rules);

            ParsingOptions opt          = genScore.GetParseOption();
            bool           reverseOrder = Tools.CheckParsingOption(opt, ParsingOptions.Reverse);
            bool           wordWrap     = Tools.CheckParsingOption(opt, ParsingOptions.WordWrap);

            int lineNumber = -1;
            // for all the rows
            IList <string[]> controls = new List <string[]>();
            int totalLines            = labels.Count(p => p != null && p[0] != ScoreCenterPlugin.C_HEADER);

            foreach (string[] row_ in labels)
            {
                // ignore empty lines
                if (row_ == null || row_.Length == 0)
                {
                    continue;
                }

                lineNumber++;

                bool     isHeader = (row_[0] == ScoreCenterPlugin.C_HEADER);
                string[] row      = isHeader ? row_.Where(c => c != ScoreCenterPlugin.C_HEADER).ToArray() : row_;

                // Evaluate rule for full line
                if (!isHeader)
                {
                    Rule rule = engine.CheckLine(row, lineNumber, totalLines);
                    if (rule != null)
                    {
                        // skip lines and continue
                        if (rule.Action == RuleAction.SkipLine)
                        {
                            continue;
                        }
                    }
                }

                #region For all columns
                for (int index = 0; index < row.Length; index++)
                {
                    int colIndex = reverseOrder ? row.Length - index - 1 : index;

                    // get cell
                    string cell = row[colIndex];

                    #region Evaluate rule for the cell
                    if (!isHeader)
                    {
                        IList <Rule> cellRules = engine.CheckCell(cell, colIndex);
                        foreach (var cellRule in cellRules)
                        {
                            cell = RuleProcessor.Process(cell, cellRule);
                        }
                    }
                    #endregion

                    row[colIndex] = cell;
                }
                #endregion

                // create the control
                controls.Add(row);
            }

            return(controls.ToArray());
        }
Example #2
0
        public override IList <T> Build(BaseScore score, string[][] labels, int startLine, int startColumn,
                                        int startX, int startY, int pnlWidth, int pnlHeight,
                                        CreateControlDelegate <T> createControl,
                                        out bool overRight, out bool overDown, out int lineNumber, out int colNumber)
        {
            lineNumber = -1;
            colNumber  = -1;
            overRight  = false;
            overDown   = false;

            //Tools.LogMessage("X = {0}, Y = {1}, W = {2}, H = {3}", startX, startY, pnlWidth, pnlHeight);

            GenericScore genScore = score as GenericScore;

            if (genScore == null)
            {
                return(null);
            }

            int maxX          = startX + pnlWidth;
            int maxY          = startY + pnlHeight;
            int posX          = startX;
            int posY          = startY;
            int maxColumnSize = pnlWidth / m_charWidth;

            // Get Columns Sizes
            ColumnDisplay[] cols = GetSizes(genScore, labels);

            RuleEvaluator engine = new RuleEvaluator(genScore.Rules);

            ParsingOptions opt          = genScore.GetParseOption();
            bool           reverseOrder = Tools.CheckParsingOption(opt, ParsingOptions.Reverse);
            bool           wordWrap     = Tools.CheckParsingOption(opt, ParsingOptions.WordWrap);

            // for all the rows
            IList <T> controls   = new List <T>();
            int       totalLines = labels.Count(p => p != null && p[0] != ScoreCenterPlugin.C_HEADER);

            foreach (string[] row_ in labels)
            {
                // ignore empty lines
                if (row_ == null || row_.Length == 0)
                {
                    continue;
                }

                lineNumber++;

                // ignore lines on previous page
                if (lineNumber < startLine)
                {
                    continue;
                }

                // calculate X position
                posX = startX;// -startColumn;

                // ignore if outside and break to next row
                if (LimitToPage && posY > maxY)
                {
                    overDown = true;
                    break;
                }

                bool     isHeader = (row_[0] == ScoreCenterPlugin.C_HEADER);
                string[] row      = isHeader ? row_.Where(c => c != ScoreCenterPlugin.C_HEADER).ToArray() : row_;

                #region Evaluate rule for full line
                //bool isHeader = !String.IsNullOrEmpty(this.Score.Headers) && lineNumber == 0;
                Style lineStyle = (lineNumber % 2 == 0) ? m_defaultStyle : m_altStyle;
                bool  merge     = false;
                if (!isHeader)
                {
                    Rule rule = engine.CheckLine(row, lineNumber, totalLines);
                    if (rule != null)
                    {
                        // skip lines and continue
                        if (rule.Action == RuleAction.SkipLine)
                        {
                            continue;
                        }

                        merge     = rule.Action == RuleAction.MergeCells;
                        lineStyle = FindStyle(rule.Format) ?? lineStyle;
                    }
                }
                #endregion

                #region For all columns
                int nbLines    = 1;
                int nbControls = 0;
                for (int index = startColumn; index < row.Length; index++)
                {
                    int colIndex = reverseOrder ? row.Length - index - 1 : index;

                    // get cell
                    string        cell    = row[colIndex];
                    ColumnDisplay colSize = GetColumnSize(colIndex, cols, cell, merge);
                    if (colSize.Size == 0)
                    {
                        continue;
                    }

                    // ignore controls outside area
                    if (LimitToPage && posX > maxX)
                    {
                        overRight = true;
                        continue;
                    }

                    // evaluate size of the control in pixel
                    int maxChar = Math.Min(colSize.Size + 1, maxColumnSize);

                    // wrap needed?
                    if (wordWrap || AutoWrap)
                    {
                        int i = maxChar + 1;
                        while (i < cell.Length)
                        {
                            cell = cell.Insert(i, Environment.NewLine);
                            i   += maxChar + 1;
                        }
                    }

                    // count new lines
                    int nb = Tools.CountLines(cell);
                    nbLines = Math.Max(nbLines, nb);

                    int length = m_charWidth * maxChar;
                    int height = m_charHeight * nbLines;
                    if (posX < startX)
                    {
                        // cell was on previous page
                        // increase posX so that we can get to current page
                        posX += length;
                        continue;
                    }

                    #region Evaluate rule for the cell
                    Style cellStyle = lineStyle;
                    if (!isHeader)
                    {
                        IList <Rule> cellRules = engine.CheckCell(cell, colIndex);
                        foreach (var cellRule in cellRules)
                        {
                            cell = RuleProcessor.Process(cell, cellRule);
                            if (cellRule != null && cellRule.Action == RuleAction.FormatCell)
                            {
                                cellStyle = FindStyle(cellRule.Format) ?? lineStyle;
                            }
                        }
                    }
                    #endregion

                    // create the control
                    string[] aa = cell.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                    for (int i = 0; i < aa.Length; i++)
                    {
                        T control = createControl(posX, posY + (i * m_charHeight), length, m_charHeight,
                                                  colSize.Alignement,
                                                  aa[i],
                                                  m_fontName, m_fontSize, cellStyle, maxChar, colIndex);

                        if (control != null)
                        {
                            controls.Add(control);
                            nbControls++;
                        }
                    }

                    // set X pos to the end of the control
                    posX += Math.Min(length, pnlWidth - 1);
                }
                #endregion

                // set Y pos to the bottom of the control
                if (nbControls > 0 || isHeader)
                {
                    posY += m_charHeight * nbLines;
                }
            }

            Tools.LogMessage("{0}: {1} controls created", score.Id, controls.Count);
            return(controls);
        }