Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try {
                List <string> lines   = textBox3.Lines.ToList();
                List <string> cleared = _calcBuilder.getCleaned(lines);

                cleared.Insert(0, "{");
                cleared.Add("}");

                CalculationItem      item  = _calcBuilder.Create(cleared);
                CalculationItemStack stack = new CalculationItemStack();
                item.Calculate(stack);

                EquationBlock block = new EquationBlock();
                foreach (CalculationItem stackItem in stack.Items)
                {
                    if (stackItem is Equation)
                    {
                        block.Equations.Add(stackItem);
                    }
                }

                _multiElement = _converter.Convert(block);
                panel2.Invalidate();
            } catch (Exception exc) {
                MessageBox.Show(exc.ToString(), "Bład", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        public Element Convert(CalculationItem item)
        {
            if (item is EquationBlock)
            {
                EquationBlock bl = (EquationBlock)item;

                EquationBlockElement blockElement = new EquationBlockElement();
                foreach (CalculationItem eq in bl.Equations)
                {
                    Element eqElem = (Element)Convert(eq);
                    blockElement.Arguments.Add(eqElem);
                }

                return(blockElement);
            }

            if (item is Equation)
            {
                Equation eq = (Equation)item;

                EquationElement eqElem = new EquationElement();
                if (null != eq.Symbol)
                {
                    eqElem.Arguments.Add(Convert(eq.Symbol));
                }
                if (null != eq.Symbolic)
                {
                    eqElem.Arguments.Add(Convert(eq.Symbolic));
                }
                if (null != eq.Numbers)
                {
                    eqElem.Arguments.Add(Convert(eq.Numbers));
                }
                if (null != eq.Value)
                {
                    eqElem.Arguments.Add(Convert(eq.Value));
                }
                return(eqElem);
            }

            return(null);
        }
Ejemplo n.º 3
0
        public override bool TryCreate(List <string> lines, CalculationBuilder builder, out CalculationItem item)
        {
            bool isMatch = (lines.First() == "{");

            if (!isMatch)
            {
                item = null;
                return(false);
            }


            EquationBlock block = new EquationBlock();

            int level = 0;

            builder.RemoveLines(lines, 1);
            for ( ; ;)
            {
                CalculationItem eq = builder.Create(lines);
                block.Equations.Add(eq);

                string currentLine = lines.First();
                if (currentLine == "}")
                {
                    if (level == 0)
                    {
                        break;
                    }
                    else
                    {
                        level--;
                    }
                }
            }

            builder.RemoveLines(lines, 1);
            item = block;
            return(true);
        }