Exemplo n.º 1
0
        private void buttonCalc_Click(object sender, EventArgs e)
        {
            // try
            // {
            MathFormula f = new MathFormula(panel.Performer.Formula, UndrawableConverter.Object);

//                MathFormula f = MathFormula.FromString(panel.Performer.Formula.Sizes, fs);
            f = f.FullTransform(null);

            /*FormulaTree tree = new FormulaTree(f);
             * FormulaTree der = tree.Deriv(textBoxDerivType.Text);
             * der.SimplifyAll();
             * derivFormula = der.GetFormula(0, FormulaEditorPanel.sizes);*/
            ObjectFormulaTree tree = ObjectFormulaTree.CreateTree(f, ElementaryFunctionsCreator.Object);
            ObjectFormulaTree der  = tree.Derivation(textBoxDerivType.Text);
            //der = ElementaryFormulaSimplification.Object.Simplify(der);//der.SimplifyAll();
            MathFormula form = FormulaCreator.CreateFormula(der, (byte)0, MathSymbolFactory.Sizes);

            form.Simplify();

            derivFormula          = new MathFormulaDrawable(form, DrawableConverter.Object);
            derivFormula.Position = pointDeriv;
            derivFormula.CalculateFullRelativeRectangle();
            derivFormula.CalculatePositions();
            paintDeriv();
            Refresh();

            /*    }
             *  catch (System.Exception ex)
             *  {
             *      WindowsExtensions.ControlExtensions.ShowMessageBoxModal(this, ex.Message);
             *  }*/
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates image from formula
        /// </summary>
        /// <param name="formula">Formula</param>
        /// <returns>Image</returns>
        public static Image CreateImage(string formula)
        {
            Image    im = new Bitmap(10, 10);
            Graphics g  = Graphics.FromImage(im);

            SimpleSymbolDrawable.Prepare(new int[] { 8, 6, 5, 4 }, g);
            MathFormulaDrawable f = new MathFormulaDrawable(MathFormula.FromString(new int[] { 8, 6, 5, 4 }, formula), DrawableConverter.Object);

            f.CalculateFullRelativeRectangle();
            Rectangle r = f.FullRelativeRectangle;
            Point     p = new Point(10, -r.Y);

            f.Position = p;
            f.CalculatePositions();
            im = new Bitmap(r.Width + 20, r.Height);
            Brush brush = new SolidBrush(Color.White);

            g = Graphics.FromImage(im);
            g.FillRectangle(brush, 0, 0, im.Width, im.Height);
            f.Draw(g);
            SimpleSymbolDrawable.Prepare(MathSymbolFactory.Sizes, g);
            g.Dispose();
            return(im);
        }