Exemple #1
0
        public void BindToOrigin()
        {
            // find the correct node (s)
            OverlayNode on1 = null, on2 = null;

            if (tikzitem.parent is Tikz_Controls) //lineToOrigin1 == null && lineToOrigin2 == null &&
            {
                Tikz_Controls pa = tikzitem.parent as Tikz_Controls;
                foreach (OverlayShape o in pol.GetAllDescendants(null))
                {
                    if (o is OverlayNode)
                    {
                        if ((o as OverlayNode).tikzitem == pa.CoordBefore)
                        {
                            on1 = o as OverlayNode;
                        }
                        else if ((o as OverlayNode).tikzitem == pa.CoordAfter)
                        {
                            on2 = o as OverlayNode;
                        }
                    }
                }

                if (pa.FirstCP == tikzitem && on1 != null)    // bind to first
                {
                    //lineToOrigin1 = new Line() { Stroke = Brushes.Gray, StrokeDashArray = new DoubleCollection(new double[] { 4, 4 }) };
                    //Canvas.SetZIndex(lineToOrigin1, -1);
                    Origin1 = on1;
                    on_PositionChanged(on1);
                    //pol.canvas.Children.Add(lineToOrigin1);
                    //lineToOrigin1.Visibility = Visibility.Visible;
                    on1.PositionChanged += new PositionChangedHandler(on_PositionChanged);
                }
                if (pa.LastCP == tikzitem && on2 != null)    // bind to second
                {
                    //lineToOrigin2 = new Line() { Stroke = Brushes.Gray, StrokeDashArray = new DoubleCollection(new double[] { 4, 4 }) };
                    //Canvas.SetZIndex(lineToOrigin2, -1);
                    Origin2 = on2;
                    on_PositionChanged(on2);
                    //pol.canvas.Children.Add(lineToOrigin2);
                    //lineToOrigin2.Visibility = Visibility.Visible;
                    on2.PositionChanged += new PositionChangedHandler(on_PositionChanged);
                }
            }
        }
Exemple #2
0
        static bool FillItem(TikzContainerParseItem item, CommonTree t, CommonTokenStream tokens)
        {
            int curToken = t.TokenStartIndex;

            if (item is Tikz_ParseTree)
            {
                curToken = 0;   // for root, start at the beginning
            }
            if (t.Children == null)
            {
                return(false);
            }

            foreach (CommonTree childt in t.Children)
            {
                addSomething(item, tokens, curToken, childt.TokenStartIndex - 1);

                switch (childt.Type)
                {
                case simpletikzParser.IM_PICTURE:
                    Tikz_Picture tp = new Tikz_Picture();
                    FillItem(tp, childt, tokens);
                    item.AddChild(tp);
                    break;

                case simpletikzParser.IM_STARTTAG:
                    item.starttag = getTokensString(tokens, childt.TokenStartIndex, childt.TokenStopIndex);
                    break;

                case simpletikzParser.IM_ENDTAG:
                    item.endtag = getTokensString(tokens, childt.TokenStartIndex, childt.TokenStopIndex);
                    break;

                case simpletikzParser.IM_PATH:
                    Tikz_Path tpath = new Tikz_Path();
                    FillItem(tpath, childt, tokens);
                    item.AddChild(tpath);
                    break;

                case simpletikzParser.IM_SCOPE:
                    Tikz_Scope tscope = new Tikz_Scope();
                    FillItem(tscope, childt, tokens);
                    item.AddChild(tscope);
                    break;

                case simpletikzParser.IM_COORD:
                    Tikz_Coord tc = Tikz_Coord.FromCommonTree(childt, tokens);
                    tc.text = getTokensString(tokens, childt);
                    item.AddChild(tc);
                    break;

                case simpletikzParser.IM_ARC:
                    Tikz_Arc ta = Tikz_Arc.FromCommonTree(childt, tokens);
                    ta.text = getTokensString(tokens, childt);
                    item.AddChild(ta);
                    break;

                case simpletikzParser.IM_NODE:
                    Tikz_Node tn = Tikz_Node.FromCommonTree(childt, tokens);
                    tn.text = getTokensString(tokens, childt);
                    item.AddChild(tn);
                    break;

                case simpletikzParser.IM_OPTION_KV:
                case simpletikzParser.IM_OPTION_STYLE:
                    Tikz_Option topt = Tikz_Option.FromCommonTree(childt, tokens);
                    if (topt == null)
                    {
                        break;
                    }
                    //topt.text = getTokensString(tokens, childt);
                    String s = getTokensString(tokens, childt);
                    topt.text = s;
                    item.AddChild(topt);
                    break;

                case simpletikzParser.IM_OPTIONS:
                    //Tikz_Options to = Tikz_Options.FromCommonTree(childt);
                    Tikz_Options to = new Tikz_Options();
                    FillItem(to, childt, tokens);
                    item.AddChild(to);
                    //to.text = getTokensString(tokens, childt);
                    //item.AddChild(tn);
                    if (item.options == null)
                    {
                        // determine whether option belongs to the item (e.g. \draw [this belongs to draw] blabla [thisnot])
                        // i.e., the scope of the options is the whole item's body
                        // this is hacky
                        if (item.Children.Count == 1 ||
                            (item.Children.Count == 2 && (item.Children[0] is Tikz_Something) &&
                             item.Children[0].ToString().Trim() == ""))
                        {
                            item.options = to;
                        }
                    }
                    break;

                case simpletikzParser.IM_TIKZSET:
                    Tikz_Options to2 = new Tikz_Options();
                    FillItem(to2, childt, tokens);
                    item.AddChild(to2);
                    break;

                case simpletikzParser.IM_STYLE:
                    Tikz_Option topt2 = Tikz_Option.FromCommonTree(childt, tokens);
                    //FillItem(to2, childt, tokens);
                    topt2.text = getTokensString(tokens, childt);
                    item.AddChild(topt2);
                    break;

                case simpletikzParser.IM_CONTROLS:
                    Tikz_Controls tcontrols = new Tikz_Controls();
                    FillItem(tcontrols, childt, tokens);
                    item.AddChild(tcontrols);
                    break;

                case simpletikzParser.IM_SIZE:
                    Tikz_Size tsize = Tikz_Size.FromCommonTree(childt, tokens);
                    tsize.text = getTokensString(tokens, childt);
                    item.AddChild(tsize);
                    //Tikz_Size tsize = new Tikz_Size();
                    //item.AddChild(tsize);
                    break;

                //case simpletikzParser.ID:
                //case simpletikzParser.IM_STRING:
                //case simpletikzParser.COMMAND:
                //case simpletikzParser.T__57:
                //    break;
                case simpletikzParser.IM_TIKZEDT_CMD:
                    Tikz_EdtCommand cmd = new Tikz_EdtCommand(getTokensString(tokens, childt));
                    item.AddChild(cmd);
                    break;

                case simpletikzParser.IM_DONTCARE:
                    Tikz_Something st = new Tikz_Something(getTokensString(tokens, childt));
                    item.AddChild(st);
                    break;

                default:
                    // getting here is an error
                    throw new Exception(" childt.Type not handled! " + childt.Type.ToString() + " (\"" + getTokensString(tokens, childt) + "\")");
                    //break;
                }

                curToken = childt.TokenStopIndex + 1;
            }

            if (t.TokenStartIndex >= 0)   // rule out empty code
            {
                addSomething(item, tokens, curToken, t.TokenStopIndex);
            }

            return(true);
        }
Exemple #3
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            Point prast = overlay.Rasterizer.RasterizePixel(p);

            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
            {
                return;
            }

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find next tikzpicture and add
            bool lcreated;

            if (EnsureCurAddToExists(out lcreated))
            {
                {
                    // there are three states:  (i)   new path -> add coordinate
                    //                          (ii)  add controlpoints
                    //                          (iii) 2 cps's added -> add bezier segment
                    if (CPCount == 2)
                    {
                        // add controls
                        Tikz_Controls tcont = new Tikz_Controls();
                        tcont.starttag = " .. controls ";
                        tcont.endtag   = " ..";
                        Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord(), tc2 = new Parser.Tikz_Coord(); // control points
                        tc1.type = tc2.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;

                        tcont.AddChild(tc1);
                        tcont.AddChild(new Tikz_Something(" and "));
                        tcont.AddChild(tc2);

                        curAddTo.AddChild(tcont);

                        // the endpoint
                        Parser.Tikz_Coord tcend = new Parser.Tikz_Coord();
                        tcend.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                        curAddTo.AddChild(new Tikz_Something(" "));
                        curAddTo.AddChild(tcend);

                        // do it here since the coordinate calculation needs the parents' coord. transform, and the second added point
                        tcend.SetAbsPos(p);
                        tc1.SetAbsPos(CP1);
                        tc2.SetAbsPos(CP2);

                        tcont.UpdateText();
                        tcend.UpdateText();

                        // draw the added objects in the overlay
                        //       overlay.AddToDisplayTree(tcend);
                        //       overlay.AddToDisplayTree(tcont);

                        CPCount             = 0;
                        Preview_CP1.Visible = Preview_CP2.Visible = false;
                    }
                    else if (lcreated)
                    {
                        // add starting point
                        // create new coordinate
                        Parser.Tikz_Coord tc = new Parser.Tikz_Coord();
                        tc.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                        curAddTo.AddChild(tc);
                        // do it here since the coordinate calculation needs the parents' coord. transform
                        tc.SetAbsPos(new Point(p.X, p.Y)); //hack
                        curAddTo.UpdateText();
                        // draw the added object in the overlay
                        //        overlay.AddToDisplayTree(tc);

                        CPCount = 0;
                    }
                    else
                    {
                        // remember control points
                        if (CPCount == 0)
                        {
                            CP1 = p;

                            Preview_CP1.SetCenter(prast.X, prast.Y);
                            ////Canvas.SetLeft(Preview_CP1, prast.X - Preview_CP1.Width / 2);
                            ////Canvas.SetBottom(Preview_CP1, prast.Y - Preview_CP1.Height / 2);
                            ////if (!overlay.canvas.Children.Contains(Preview_CP1))
                            ////    overlay.canvas.Children.Add(Preview_CP1);
                            ////Preview_CP1.Visibility = Visibility.Visible;
                            Preview_CP1.Visible = true;
                        }
                        else if (CPCount == 1)
                        {
                            CP2 = p;
                            Preview_CP2.SetCenter(prast.X, prast.Y);
                            ////Canvas.SetLeft(Preview_CP2, prast.X - Preview_CP2.Width / 2);
                            ////Canvas.SetBottom(Preview_CP2, prast.Y - Preview_CP2.Height / 2);
                            ////if (!overlay.canvas.Children.Contains(Preview_CP2))
                            ////    overlay.canvas.Children.Add(Preview_CP2);
                            ////Preview_CP2.Visibility = Visibility.Visible;
                            Preview_CP2.Visible = true;
                        }
                        CPCount++;
                    }
                }
            }

            overlay.EndUpdate();
        }