/// <summary> /// Draws the TikzParseItem tpi, if it is drawn, or its children, if they can be drawn, /// or grandchildren etc..., and adds the drawn items to bag. /// </summary> /// <param name="tpi"></param> /// <param name="bag"></param> public void DrawObject(TikzParseItem tpi, List <OverlayShape> bag) { //BBGatherer bbg = new BBGatherer(); if (bag == null) { bag = new List <OverlayShape>(); // dummy, it is not used } if (tpi is Tikz_Scope) { OverlayScope os = new OverlayScope(ShapeFactory.NewScopeView()); os.pol = this; os.tikzitem = tpi as Tikz_Scope; foreach (TikzParseItem t in (tpi as TikzContainerParseItem).Children) { DrawObject(t, os.children); } // don't draw scopes with no drawable children // (we don't know where to render them) if (os.children.Count > 0) { bag.Add(os); os.AdjustPosition(Resolution); ////canvas1.Children.Add(os); } } else if (tpi is TikzContainerParseItem) { foreach (TikzParseItem t in (tpi as TikzContainerParseItem).Children) { DrawObject(t, bag); } } if (tpi is Tikz_XYItem) { if ((tpi as Tikz_XYItem).HasEditableCoordinate()) { OverlayNode el; if (tpi.parent is Tikz_Controls) { el = new OverlayControlPoint(ShapeFactory.NewCPView()); // control points for Bezier curves } else { el = new OverlayNode(ShapeFactory.NewNodeView()); } el.pol = this; el.tikzitem = tpi as Tikz_XYItem; //Ellipse el = new Ellipse(); //el.Stroke = Brushes.Red; el.AdjustPosition(Resolution); // add tooltip Tikz_Node nref = TikzParseTreeHelper.GetReferenceableNode(tpi as Tikz_XYItem, ParseTree.GetTikzPicture()); if (nref != null && nref.name != "") { el.View.SetToolTip(nref.name); } ////canvas1.Children.Add(el); bag.Add(el); //bbg.Add(new Rect(Canvas.GetLeft(el), Canvas.GetTop(el), el.Width, el.Height)); } } else if (tpi is Tikz_Path) { //could this be a possibility to show edges and provide backward search? //there are many possibility for draw commands. here we /* string simpleEdge_RegexString = @"[ \t\s]*\\draw.*\((?<start>.*)\).*\((?<end>.*)\).*"; * Regex BB_Regex = new Regex(simpleEdge_RegexString); * Match m = BB_Regex.Match(tpi.ToString()); * if (m.Success == true) * { * //we just found a LaTex draw cmd, e.g.: \draw[default_edge] (v91) to (v99); * * //get both nodes * Tikz_Node StartNode = tpi.parent.GetNodeByName(m.Groups[1].Value); * Tikz_Node EndNode = tpi.parent.GetNodeByName(m.Groups[2].Value); * * if (StartNode != null && EndNode != null) * { * //and determine the position in between both nodes * Point start, end; * if (StartNode.GetAbsPos() * double x = (StartNode.GetAbsPos().X + EndNode.GetAbsPos().X) / 2; * double y = (StartNode.GetAbsPos().Y + EndNode.GetAbsPos().Y) / 2; * * //draw an arrow at this pos. * //(new Point(x, y)); * //and when clicked, jump to AvalonEdit at position tpi.StartPosition * } * * } */ } }
IEnumerable<OverlayShapeVM> CreateOverlayShapesFromItem(TikzParseItem tpi) { var ret = new List<OverlayShapeVM>(); if (tpi is Tikz_Scope) { OverlayScope os = new OverlayScope(); //os.pol = this; os.tikzitem = tpi as Tikz_Scope; // add child shapes os.children.AddRange( (tpi as TikzContainerParseItem).Children.SelectMany( child => CreateOverlayShapesFromItem(child) ) ); //foreach (TikzParseItem t in (tpi as TikzContainerParseItem).Children) // DrawObject(t, os.children); // don't draw scopes with no drawable children // (we don't know where to render them) if (os.children.Count > 0) { ret.Add(os); os.AdjustPosition(TikzToScreen); } } else if (tpi is TikzContainerParseItem) { ret.AddRange( (tpi as TikzContainerParseItem).Children.SelectMany( child => CreateOverlayShapesFromItem(child) ) ); } else if (tpi is Tikz_XYItem) { if ((tpi as Tikz_XYItem).HasEditableCoordinate()) { OverlayNode el; if (tpi.parent is Tikz_Controls) el = new OverlayControlPoint(); // control points for Bezier curves else el = new OverlayNode(); //el.pol = this; el.tikzitem = tpi as Tikz_XYItem; el.AdjustPosition(TikzToScreen); // add tooltip if (ParseTree != null) { Tikz_Node nref = TikzParseTreeHelper.GetReferenceableNode(tpi as Tikz_XYItem, ParseTree.GetTikzPicture()); if (nref != null && !String.IsNullOrWhiteSpace(nref.name)) { el.ToolTip = nref.name; } } ////canvas1.Children.Add(el); ret.Add(el); //bbg.Add(new Rect(Canvas.GetLeft(el), Canvas.GetTop(el), el.Width, el.Height)); } } else if (tpi is Tikz_Path) { } return ret; }
IEnumerable <OverlayShapeVM> CreateOverlayShapesFromItem(TikzParseItem tpi) { var ret = new List <OverlayShapeVM>(); if (tpi is Tikz_Scope) { OverlayScope os = new OverlayScope(); //os.pol = this; os.tikzitem = tpi as Tikz_Scope; // add child shapes os.children.AddRange((tpi as TikzContainerParseItem).Children.SelectMany(child => CreateOverlayShapesFromItem(child))); //foreach (TikzParseItem t in (tpi as TikzContainerParseItem).Children) // DrawObject(t, os.children); // don't draw scopes with no drawable children // (we don't know where to render them) if (os.children.Count > 0) { ret.Add(os); os.AdjustPosition(TikzToScreen); } } else if (tpi is TikzContainerParseItem) { ret.AddRange((tpi as TikzContainerParseItem).Children.SelectMany(child => CreateOverlayShapesFromItem(child))); } else if (tpi is Tikz_XYItem) { if ((tpi as Tikz_XYItem).HasEditableCoordinate()) { OverlayNode el; if (tpi.parent is Tikz_Controls) { el = new OverlayControlPoint(); // control points for Bezier curves } else { el = new OverlayNode(); } //el.pol = this; el.tikzitem = tpi as Tikz_XYItem; el.AdjustPosition(TikzToScreen); // add tooltip if (ParseTree != null) { Tikz_Node nref = TikzParseTreeHelper.GetReferenceableNode(tpi as Tikz_XYItem, ParseTree.GetTikzPicture()); if (nref != null && !String.IsNullOrWhiteSpace(nref.name)) { el.ToolTip = nref.name; } } ////canvas1.Children.Add(el); ret.Add(el); //bbg.Add(new Rect(Canvas.GetLeft(el), Canvas.GetTop(el), el.Width, el.Height)); } } else if (tpi is Tikz_Path) { } return(ret); }
/// <summary> /// Draws the TikzParseItem tpi, if it is drawn, or its children, if they can be drawn, /// or grandchildren etc..., and adds the drawn items to bag. /// </summary> /// <param name="tpi"></param> /// <param name="bag"></param> public void DrawObject(TikzParseItem tpi, List<OverlayShape> bag) { //BBGatherer bbg = new BBGatherer(); if (bag == null) bag = new List<OverlayShape>(); // dummy, it is not used if (tpi is Tikz_Scope) { OverlayScope os = new OverlayScope(ShapeFactory.NewScopeView()); os.pol = this; os.tikzitem = tpi as Tikz_Scope; foreach (TikzParseItem t in (tpi as TikzContainerParseItem).Children) DrawObject(t, os.children); // don't draw scopes with no drawable children // (we don't know where to render them) if (os.children.Count > 0) { bag.Add(os); os.AdjustPosition(Resolution); ////canvas1.Children.Add(os); } } else if (tpi is TikzContainerParseItem) { foreach (TikzParseItem t in (tpi as TikzContainerParseItem).Children) DrawObject(t, bag); } if (tpi is Tikz_XYItem) { if ((tpi as Tikz_XYItem).HasEditableCoordinate()) { OverlayNode el; if (tpi.parent is Tikz_Controls) el = new OverlayControlPoint(ShapeFactory.NewCPView()); // control points for Bezier curves else el = new OverlayNode(ShapeFactory.NewNodeView()); el.pol = this; el.tikzitem = tpi as Tikz_XYItem; //Ellipse el = new Ellipse(); //el.Stroke = Brushes.Red; el.AdjustPosition(Resolution); // add tooltip Tikz_Node nref = TikzParseTreeHelper.GetReferenceableNode(tpi as Tikz_XYItem, ParseTree.GetTikzPicture()); if (nref != null && nref.name != "") { el.View.SetToolTip(nref.name); } ////canvas1.Children.Add(el); bag.Add(el); //bbg.Add(new Rect(Canvas.GetLeft(el), Canvas.GetTop(el), el.Width, el.Height)); } } else if (tpi is Tikz_Path) { //could this be a possibility to show edges and provide backward search? //there are many possibility for draw commands. here we /* string simpleEdge_RegexString = @"[ \t\s]*\\draw.*\((?<start>.*)\).*\((?<end>.*)\).*"; Regex BB_Regex = new Regex(simpleEdge_RegexString); Match m = BB_Regex.Match(tpi.ToString()); if (m.Success == true) { //we just found a LaTex draw cmd, e.g.: \draw[default_edge] (v91) to (v99); //get both nodes Tikz_Node StartNode = tpi.parent.GetNodeByName(m.Groups[1].Value); Tikz_Node EndNode = tpi.parent.GetNodeByName(m.Groups[2].Value); if (StartNode != null && EndNode != null) { //and determine the position in between both nodes Point start, end; if (StartNode.GetAbsPos() double x = (StartNode.GetAbsPos().X + EndNode.GetAbsPos().X) / 2; double y = (StartNode.GetAbsPos().Y + EndNode.GetAbsPos().Y) / 2; //draw an arrow at this pos. //(new Point(x, y)); //and when clicked, jump to AvalonEdit at position tpi.StartPosition } } */ } }
OverlayCPView NewCPView(OverlayControlPoint ocp) { OverlayCPView v = new OverlayCPView(ocp); canvas1.Children.Add(v); canvas1.Children.Add(v.lineToOrigin1); canvas1.Children.Add(v.lineToOrigin2); return v; }