Esempio n. 1
0
        public UserControl1()
        {
            InitializeComponent();
            _userControlStatus = UserControlStatus.None;

            _mrec = new MathRecognition(_mathStroqs);
            _mrec.EnsureLoaded(); // this is optional, and should only be called once per program run
            _mrec.ParseUpdated += _mrec_ParseUpdated;

            _altsMenuCrea = new AlternatesMenuCreator(alternatesMenu, _mrec);
        
            //inqCanvas.StroqCollected += inqCanvas_StroqCollected;
            //inqCanvas.PreviewStylusDown += inqCanvas_PreviewStylusDown;
            //inqCanvas.PreviewMouseLeftButtonDown += inqCanvas_PreviewMouseLeftButtonDown;
            //inqCanvas.PreviewMouseMove += inqCanvas_PreviewMouseMove;
            //inqCanvas.PreviewMouseLeftButtonUp += inqCanvas_PreviewMouseLeftButtonUp;
            //inqCanvas.PreviewStylusButtonUp += inqCanvas_PreviewStylusUp;

            inqCanvas.DefaultDrawingAttributes.Width = 1;

            /* for the rest of this method, try to ensure more stuff is loaded at startup to avoid a long pause after first stroke */
            // load unicode stuff (may not be that long?)
            Console.WriteLine(Unicode.NameOf('a'));

            // load drawing wpf stuff and create initial math font stuff            
            DrawingVisual dv = new DrawingVisual();
            var dc = dv.RenderOpen();
            Rct nombb = starPadSDK.MathExpr.ExprWPF.EWPF.DrawTop(new LetterSym('1'), 22, dc, Colors.Blue, new Pt(0, 0), true);
            dc.Close();
        }
Esempio n. 2
0
        public Window1()
        {
            InitializeComponent();
            _mrec = new MathRecognition(_mathStroqs);

            _mrec.ParseUpdated += _mrec_ParseUpdated;

            _altsMenuCrea = new AlternatesMenuCreator(alternatesMenu, _mrec);

            inqCanvas.StroqCollected             += inqCanvas_StroqCollected;
            inqCanvas.PreviewStylusDown          += inqCanvas_PreviewStylusDown;
            inqCanvas.PreviewMouseLeftButtonDown += inqCanvas_PreviewMouseLeftButtonDown;
            inqCanvas.PreviewMouseMove           += inqCanvas_PreviewMouseMove;
            inqCanvas.PreviewMouseLeftButtonUp   += inqCanvas_PreviewMouseLeftButtonUp;
        }
Esempio n. 3
0
        /* colorize ink. Ideally we would have kept track of which ink strokes had changes and only update colorization in those ranges affected
         * by the changes. */
        /// <summary>
        /// This colorizes the ink from scratch, but state is maintained across all of the calls.
        /// </summary>
        public void Colorize(MathRecognizer.Line math, Strokes strokes, MathRecognition mrec)
        {
            HashSet <Recognition> recs = new HashSet <Recognition>(new RecogGuidEqual());

            foreach (var s in strokes)
            {
                Recognition r = mrec.Charreco.Classification(s);
                if (r != null)
                {
                    recs.Add(r);
                }
            }
            foreach (var r in recs)
            {
                Symbol sym = FindSymbol(math, r);
                if (sym == null)
                {
                    continue;
                }
                string npath = FindPath(math, sym.r);
                string opath;
                if (!_oldPaths.TryGetValue(sym.r.strokes[0].Id, out opath) || opath != npath)
                {
                    ComputePaintColors(math, sym.r);
                }
                _oldPaths[sym.r.strokes[0].Id] = npath;
            }
            // paint expression using current color keys
            recs.Clear();
            foreach (var s in strokes)
            {
                if (!s.Deleted)
                {
                    Recognition r = mrec.Charreco.Classification(s);
                    if (r != null)
                    {
                        recs.Add(r);
                    }
                }
            }
            foreach (var r in recs)
            {
                string path = FindPath(math, r);
                foreach (var s in r.strokes)
                {
                    if (s.Deleted)
                    {
                        continue;
                    }
                    colTime ct;
                    if (path == "")
                    {
                        mrec.Sim[s].BackingStroke.DrawingAttributes.Color = Colors.Yellow;
                    }
                    else if (_recent.TryGetValue(path, out ct))
                    {
                        mrec.Sim[s].BackingStroke.DrawingAttributes.Color = ct.col;
                    }
                    else
                    {
                        mrec.Sim[s].BackingStroke.DrawingAttributes.Color = Colors.Black;
                    }
                }
            }
        }
Esempio n. 4
0
        private void _mrec_ParseUpdated(MathRecognition source, Recognition chchanged, bool updateMath)
        {
            /* Evaluate math if necessary */
            if (updateMath)
            {
                try
                {
                    Evaluator.UpdateMath(_mrec.Ranges.Select((Parser.Range r) => r.Parse));
                }
                catch { }
            }

            /* reset geometry displayed: range displays, etc */
            underlay.Children.Clear();
            inqCanvas.Children.Clear();

            /* set up to draw background yellow thing for range displays */
            Brush fill3 = new SolidColorBrush(Color.FromArgb(50, 255, 255, 180));
            Brush fill2 = new SolidColorBrush(Color.FromArgb(75, 255, 255, 180));
            Brush fill1 = new SolidColorBrush(Color.FromArgb(100, 255, 255, 180));
            Brush sqr3  = new SolidColorBrush(Color.FromArgb(50, 0, 255, 0));
            Brush sqr2  = new SolidColorBrush(Color.FromArgb(75, 0, 255, 0));
            Brush sqr1  = new SolidColorBrush(Color.FromArgb(100, 0, 255, 0));

            foreach (Parser.Range rrr in _mrec.Ranges)
            {
                Rct rangebbox = bbox(rrr.Strokes);
                Rct box       = rangebbox.Inflate(8, 8);

                /* draw yellow box */
                DrawingVisual  dv = new DrawingVisual();
                DrawingContext dc = dv.RenderOpen();
                dc.DrawRoundedRectangle(fill3, null, box, 4, 4);
                dc.DrawRoundedRectangle(fill2, null, box.Inflate(-4, -4), 4, 4);
                dc.DrawRoundedRectangle(fill1, null, box.Inflate(-8, -8), 4, 4);
                dc.Close();
                underlay.Children.Add(dv);

                if (rrr.Parse != null)
                {
                    /* draw interpretation of entry */
                    if (rrr.Parse.expr != null)
                    {
                        dv = new DrawingVisual();
                        dc = dv.RenderOpen();
                        // this is an example of normal drawing of an expr
                        Rct nombb = starPadSDK.MathExpr.ExprWPF.EWPF.DrawTop(rrr.Parse.expr, 22, dc, Colors.Blue, new Pt(box.Left, box.Bottom + 24), true).rect;

                        dc.Close();
                        underlay.Children.Add(dv);
                    }

                    /* draw result of computation, if any */
                    if (rrr.Parse.finalSimp != null)
                    {
                        Rct  nombb;
                        Expr result = rrr.Parse.matrixOperationResult == null ? rrr.Parse.finalSimp : rrr.Parse.matrixOperationResult;
                        // this is an example of drawing an expr by getting a geometry of it first, so can be used for special effects, etc.
                        Geometry g = starPadSDK.MathExpr.ExprWPF.EWPF.ComputeGeometry(result, 22, out nombb);
                        System.Windows.Shapes.Path p = new System.Windows.Shapes.Path();
                        p.Data            = g;
                        p.Stroke          = Brushes.Red;
                        p.Fill            = Brushes.Transparent;
                        p.StrokeThickness = 1;
                        p.RenderTransform = new TranslateTransform(box.Right + 10, box.Center.Y);
                        inqCanvas.Children.Add(p);
                    }

                    /* colorize ink. Ideally we would have kept track of which ink strokes had changes and only update colorization in those ranges affected
                     * by the changes. */
                    if (rrr.Parse.root != null)
                    {
                        _colorizer.Colorize(rrr.Parse.root, rrr.Strokes, _mrec);
                    }
                }
            }

            /* Update alternates menu if user wrote a char */
            if (chchanged != null)
            {
                showSidebarAlts(new[] { chchanged }, new StroqCollection(_mrec.Sim[chchanged.strokes]));
            }
        }
Esempio n. 5
0
 public AlternatesMenuCreator(ToolBar menushell, MathRecognition mrec)
 {
     _menuShell = menushell;
     _mrec      = mrec;
 }
Esempio n. 6
0
 abstract public void Reparse(MathRecognition mrec);
Esempio n. 7
0
 public override void Reparse(MathRecognition mrec)
 {
     mrec.ReRecogParse(mrec.Sim[AllStroqs], true);
 }
Esempio n. 8
0
 abstract public void Reparse(MathRecognition mrec);
Esempio n. 9
0
 public override void Reparse(MathRecognition mrec)
 {
     mrec.ReRecogParse(mrec.Sim[AllStroqs], true);
 }
Esempio n. 10
0
        private void _mrec_ParseUpdated(MathRecognition source, Recognition chchanged, bool updateMath)
        {
            /* Evaluate math if necessary */
            if (updateMath)
                try
                {
                    Evaluator.UpdateMath(_mrec.Ranges.Select((Parser.Range r) => r.Parse));
                }
                catch { }

            /* reset geometry displayed: range displays, etc */
            underlay.Children.Clear();
            inqCanvas.Children.Clear();

            /* set up to draw background yellow thing for range displays */
            Brush fill3 = new SolidColorBrush(Color.FromArgb(50, 255, 255, 180));
            Brush fill2 = new SolidColorBrush(Color.FromArgb(75, 255, 255, 180));
            Brush fill1 = new SolidColorBrush(Color.FromArgb(100, 255, 255, 180));
            Brush sqr3 = new SolidColorBrush(Color.FromArgb(50, 0, 255, 0));
            Brush sqr2 = new SolidColorBrush(Color.FromArgb(75, 0, 255, 0));
            Brush sqr1 = new SolidColorBrush(Color.FromArgb(100, 0, 255, 0));
            foreach (Parser.Range rrr in _mrec.Ranges)
            {
                Rct rangebbox = bbox(rrr.Strokes);
                CurrentStrokesBoudningBox = rangebbox;

                Rct box = rangebbox.Inflate(8, 8);

                /* draw yellow box */
                DrawingVisual dv = new DrawingVisual();
                DrawingContext dc = dv.RenderOpen();
                dc.DrawRoundedRectangle(fill3, null, box, 4, 4);
                dc.DrawRoundedRectangle(fill2, null, box.Inflate(-4, -4), 4, 4);
                dc.DrawRoundedRectangle(fill1, null, box.Inflate(-8, -8), 4, 4);
                dc.Close();
                underlay.Children.Add(dv);

                if (rrr.Parse != null)
                {
                    /* draw interpretation of entry */
                    if (rrr.Parse.expr != null)
                    {
                        dv = new DrawingVisual();
                        dc = dv.RenderOpen();
                        // this is an example of normal drawing of an expr
                        Rct nombb = starPadSDK.MathExpr.ExprWPF.EWPF.DrawTop(rrr.Parse.expr, 22, dc, Colors.Blue, new Pt(box.Left, box.Bottom + 24), true);
                        dc.Close();
                        underlay.Children.Add(dv);
                    }

                    /* draw result of computation, if any */
                    if (rrr.Parse.finalSimp != null)
                    {
                        Rct nombb;
                        Expr result = rrr.Parse.matrixOperationResult == null ? rrr.Parse.finalSimp : rrr.Parse.matrixOperationResult;
                        // this is an example of drawing an expr by getting a geometry of it first, so can be used for special effects, etc.
                        Geometry g = starPadSDK.MathExpr.ExprWPF.EWPF.ComputeGeometry(result, 22, out nombb);
                        System.Windows.Shapes.Path p = new System.Windows.Shapes.Path();
                        p.Data = g;
                        p.Stroke = Brushes.Red;
                        p.Fill = Brushes.Transparent;
                        p.StrokeThickness = 1;
                        p.RenderTransform = new TranslateTransform(box.Right + 10, box.Center.Y);
                        inqCanvas.Children.Add(p);
                    }

                    /* colorize ink. Ideally we would have kept track of which ink strokes had changes and only update colorization in those ranges affected
                     * by the changes. */
                    if (rrr.Parse.root != null) _colorizer.Colorize(rrr.Parse.root, rrr.Strokes, _mrec);
                }
            }

            /* Update alternates menu if user wrote a char */
            if (chchanged != null)
            {
                showSidebarAlts(new[] { chchanged }, new StroqCollection(_mrec.Sim[chchanged.strokes]));
            }
#if false
            /* print out log of current 1st-level parse, for debugging */
            List<string> resstrs = new List<string>();
            foreach(Parser.Range r in _mrec.Ranges) {
                Parser.ParseResult p = r.Parse;
                if(p != null && p.root != null)
                    resstrs.Add(p.root.Print());
            }
            if(resstrs.Count > 0) Console.WriteLine(resstrs.Aggregate((string a, string b) => a + " // " + b));
            foreach(Parser.Range r in _mrec.Ranges) {
                Parser.ParseResult pr = r.Parse;
                if(pr != null && pr.expr != null) Console.WriteLine(Text.Convert(pr.expr));
            }
#endif
        }