Пример #1
0
        private Tuple <int, int> DrawTruthTable(Graphics g)
        {
            int x = TruthTableOffsetX - SpaceBetweenTokens + 10;
            int y;

            int[] drawingPositionsX = new int[_logicalExpression.Expression.Length];
            var   tokens            = _logicalExpression.GetInfixTokens().ToArray();

            using (Font font = new Font(FontName, FontSize))
            {
                var previousTokenType = tokens[0].Item1;

                foreach (var token in tokens)
                {
                    TokenType tokenType     = token.Item1;
                    char      tokenValue    = token.Item2;
                    int       tokenPosition = token.Item3;

                    if (tokenType == TokenType.Implication || tokenType == TokenType.Conjunction || tokenType == TokenType.Disjunction ||
                        previousTokenType == TokenType.Implication || previousTokenType == TokenType.Conjunction ||
                        previousTokenType == TokenType.Disjunction)
                    {
                        x += SpaceBetweenImplications;
                    }
                    else
                    {
                        x += SpaceBetweenTokens;
                    }

                    g.DrawString(tokenValue.ToString(), font, Brushes.Blue, x, TruthTableOffsetY);
                    drawingPositionsX[tokenPosition] = x;

                    previousTokenType = tokenType;
                }

                y = TruthTableOffsetY;

                for (int row = 0; row < _logicalExpression.TruthTable.Length; row++)
                {
                    string result = _logicalExpression.TruthTable[row];

                    y += SpaceBetweenRows;
                    for (int i = 0; i < result.Length; i++)
                    {
                        Brush brush = i == _logicalExpression.TruthTable.ResultPosition ? Brushes.Red : Brushes.Black;
                        g.DrawString(result[i].ToString(), font, brush, drawingPositionsX[i], y);
                    }
                }
            }

            // Returns position of last column and row of the truth table in order to know how long the truth table's lines have to be.
            return(new Tuple <int, int>(x, y));
        }