Example #1
0
   /*     public static void SetShiftRel(TikzContainerParseItem tcpi, double xshift, double yshift)
        {
            if (xshift != 0)
            {
                Tikz_Option o = GetOption(tcpi, "xshift", Tikz_OptionType.keyval);
                if (o == null)
                {
                    o = new Tikz_Option();
                    o.type = Tikz_OptionType.keyval;
                    o.key = "xshift";
                    o.numval = new Tikz_NumberUnit();
                    o.numval.unit = "cm";
                    o.numval.SetInCM(xshift);
                    AddOption(tcpi, o);
                }
                else
                {
                    o.numval.SetInCM(o.numval.GetInCM() + xshift);
                    o.UpdateText();
                }
            }
            if (yshift != 0)
            {
                Tikz_Option o = GetOption(tcpi, "yshift", Tikz_OptionType.keyval);
                if (o == null)
                {
                    o = new Tikz_Option();
                    o.type = Tikz_OptionType.keyval;
                    o.key = "yshift";
                    o.numval = new Tikz_NumberUnit();
                    o.numval.unit = "cm";
                    o.numval.SetInCM(yshift);
                    AddOption(tcpi, o);
                }
                else
                {
                    o.numval.SetInCM(o.numval.GetInCM() + yshift);
                    o.UpdateText();
                }
            }
        } */

        public static Tikz_Option GetOption(TikzContainerParseItem tcpi, string optionname, Tikz_OptionType type)
        {
            Tikz_Option to = null;
            foreach (TikzParseItem tpi in tcpi.Children)
            {
                if (tpi is Tikz_Options)
                {
                    Tikz_Option o = (tpi as Tikz_Options).GetOption(optionname, type);
                    if (o != null)
                        to = o;
                }
            }
            return to;
        }
Example #2
0
        public static void AddOption(TikzContainerParseItem tcpi, Tikz_Option o)
        {
            if (tcpi.options == null)
            {
                Tikz_Options topts = new Tikz_Options();
                tcpi.AddChild(topts, true);
                tcpi.options = topts;
            }

            tcpi.options.AddOption(o);
        }
Example #3
0
 Tikz_Picture GetTikzPicture(TikzContainerParseItem tc)
 {            
     foreach (TikzParseItem tpi in tc.Children)
     {
         if (tpi is Tikz_Picture)
             return (tpi as Tikz_Picture);
         if (tpi is TikzContainerParseItem)
         {
             Tikz_Picture ret = GetTikzPicture(tpi as TikzContainerParseItem);
             if (ret != null)
                 return ret;
         }
     }
     return null;
 }
        //create a new CurAddTo (even though their already might be one)
        //(needed for edge tool)
        protected virtual bool AddNewCurAddTo()
        {
            // find tikzpicture
            Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
            if (tpict == null)
                return false;


            Parser.Tikz_Path tp = new Parser.Tikz_Path();
            tp.starttag = @"\draw ";
            tp.endtag = ";";
            if (!String.IsNullOrEmpty(overlay.EdgeStyle))
            {
                Parser.Tikz_Options topt = new Parser.Tikz_Options();
                topt.starttag = "[";
                topt.endtag = "]";
                Parser.Tikz_Option to = new Parser.Tikz_Option();
                to.type = Parser.Tikz_OptionType.key;
                to.key = overlay.EdgeStyle;

                topt.AddOption(to);
                tp.AddChild(topt);
                tp.options = topt;
            }
            if (overlay.CurEditing != null)
            {
                overlay.CurEditing.tikzitem.AddChild(tp);
                overlay.CurEditing.tikzitem.AddChild(new Parser.Tikz_Something("\r\n"));
            }
            else
            {
                tpict.AddChild(tp);
                tpict.AddChild(new Parser.Tikz_Something("\r\n"));
            }
            curAddTo = tp;

            return true;
        }
 public override void OnDeactivate()
 {
     base.OnDeactivate();
     curAddTo = null;
 }
Example #6
0
        static void addSomething(TikzContainerParseItem item, CommonTokenStream tokens, int FirstToken, int LastToken)
        {
            if (LastToken-FirstToken < 0)
                return;

            Tikz_Something t = new Tikz_Something(getTokensString(tokens, FirstToken, LastToken));
            item.AddChild(t);            
        }
Example #7
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;
        }