Beispiel #1
0
        /// <summary>
        /// The Treenode t must have either 3 or four children
        /// </summary>
        /// <param name="t"></param>
        /// <param name="tokens"></param>
        /// <returns></returns>
        public static Tikz_Arc FromCommonTree(ITree t, CommonTokenStream tokens)
        {
            Tikz_Arc ta = new Tikz_Arc();
            if (t.ChildCount != 3 && t.ChildCount != 4)
            {
                throw new Exception("Parser returned invalid IM_ARC node.");
            }

            // if one of the children is not of type numberunit (i.e., math expression etc.), then the present arc will be marked invalid
            for (int i = 0; i < t.ChildCount; i++)
                if (t.GetChild(i).Type != simpletikzParser.IM_NUMBERUNIT)
                    ta.IsBroken = true;

            if (!ta.IsBroken)
            {
                ta.phi1 = new Tikz_NumberUnit(t.GetChild(0));
                ta.phi2 = new Tikz_NumberUnit(t.GetChild(1));
                ta.r1 = new Tikz_NumberUnit(t.GetChild(2));
                if (t.ChildCount == 4)
                {
                    ta.r2 = new Tikz_NumberUnit(t.GetChild(3));
                }
            }
            return ta;
        }
Beispiel #2
0
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e) 
        {
            if (!EnsureParseTreeExists())
                return;

            Point ptikz = overlay.Rasterizer.RasterizePixelToTikz(p);
            p = overlay.Rasterizer.RasterizePixel(p);
            if (ContinueWithBigImage(ptikz) == false)
                return;           

            if (pointcount == 0)
            {
                //overlay.SetCorrectRaster(overlay.CurEditing, true);
                center = ptikz;

                // set raster to polar, and such that origin is at center
                overlay.Rasterizer.View.IsCartesian = false;
                TikzMatrix M = overlay.Rasterizer.View.CoordinateTransform;
                M.m[0, 2] = center.X;
                M.m[1, 2] = center.Y;
                overlay.Rasterizer.View.CoordinateTransform = M;
                pointcount = 1;

                PreviewPie.center = PreviewArc.center = new Point(p.X, overlay.Height - p.Y);

                ////if (!overlay.canvas.Children.Contains(PreviewArc))
                ////    overlay.canvas.Children.Add(PreviewArc);
                ////if (!overlay.canvas.Children.Contains(PreviewPie))
                ////    overlay.canvas.Children.Add(PreviewPie);
            }
            else if (pointcount == 1)
            {
                p1 = ptikz;
                pointcount = 2;
                PreviewPie.p1 = PreviewArc.p2 = new Point(p.X, overlay.Height - p.Y);

                // compute radius 
                TikzMatrix M = overlay.Rasterizer.View.CoordinateTransform;
                Point ploc = M.Inverse().Transform(p1);
                overlay.Rasterizer.View.ForceRadiusTo = (ploc - (new Point(0, 0))).Length;

            }
            else if (pointcount == 2)
            {
                // **** create arc / pie ****
                overlay.BeginUpdate();
                // find next tikzpicture and add
                if (AddNewCurAddTo()) //(EnsureCurAddToExists(out lcreated))
                {

                    // Pie?                    
                    if (IsPie)
                    {
                        // create new coordinate
                        Tikz_Coord tc = new Parser.Tikz_Coord();
                        tc.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                        curAddTo.AddChild(tc);
                        tc.SetAbsPos(center);
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- "));
                    }

                    Tikz_Coord tc1 = new Parser.Tikz_Coord();
                    if (IsPie)
                    {
                        tc1.type = Tikz_CoordType.Polar;
                        tc1.deco = "++";
                    }
                    curAddTo.AddChild(tc1);
                    tc1.SetAbsPos(p1);
                    curAddTo.AddChild(new Parser.Tikz_Something(" "));

                    // create arc                    
                    Tikz_Arc ta = new Tikz_Arc();                    
                    curAddTo.AddChild(ta);
                    ta.SetFromPoints(center, ptikz, IsLargeArc);
                    
                    if (IsPie)
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- cycle"));

                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

                    // draw the added object in the overlay
                    overlay.AddToDisplayTree(curAddTo);

                }

                overlay.EndUpdate();

                // reset everything
                pointcount = 0;
                overlay.Rasterizer.View.ForceRadiusTo = -1;
                overlay.SetCorrectRaster(overlay.CurEditing, true);
            }
            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);
            UpdatePreviewDisplay(p);

        }