public override void OnRightMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e) { //base.OnRightMouseButtonDown(item, p, e); // if a node is selected, unselect it if (curSel != null) { curSel = null; e.Handled = true; // we don't want anything else to happen (contextmenu opening etc) } }
void on_PositionChanged(OverlayNode sender) { if (Origin1 != null) { View.SetOrigin1(Origin1.View.GetLeft(), pol.Height - Origin1.View.GetBottom(), pol.Height); } if (Origin2 != null) { View.SetOrigin2(Origin2.View.GetLeft(), pol.Height - Origin2.View.GetBottom(), pol.Height); } }
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); } } }
void on_PositionChanged(OverlayNode sender) { if (Origin1 != null) View.SetOrigin1(Origin1.View.GetLeft(), pol.Height - Origin1.View.GetBottom(), pol.Height); if (Origin2 != null) View.SetOrigin2(Origin2.View.GetLeft(), pol.Height - Origin2.View.GetBottom(), pol.Height); }
/// <summary> /// Finds the correct VMs that correspond to the endpoints of the Bezier segment in the /// provided List of known OverlayShapes. /// /// </summary> /// <param name="AllOverlayShapes"></param> public void BindToOrigin(IEnumerable<OverlayShapeVM> AllOverlayShapes) { // 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 (var o in AllOverlayShapes.OfType < OverlayNode>()) { if (o.tikzitem == pa.CoordBefore) on1 = o; else if (o.tikzitem == pa.CoordAfter) on2 = o; } 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); } } }
/// <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 * } * * } */ } }
public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e) { if (!(item is OverlayNode)) { curSel = null; return; } OverlayNode n = item as OverlayNode; // make sure a referenceable item is selected... otherwise we cannot add an edge if (!IsReferenceable(item)) { GlobalUI.UI.AddStatusLine(this, "Only items that are referenceable (=can be given names) can be connected with the edge tool."); return; } if (curSel == null) { curSel = n; return; } // make sure both nodes involved are nodes /* if (!(curSel.tikzitem is Tikz_Node) || !(n.tikzitem is Tikz_Node)) { String which = ""; String verb = "is"; if (!(curSel.tikzitem is Tikz_Node) && !(n.tikzitem is Tikz_Node)) { which = "Both"; verb = "are"; } else if (!(curSel.tikzitem is Tikz_Node)) which = "The first"; else if (!(n.tikzitem is Tikz_Node)) which = "The second"; MainWindow.AddStatusLine(which + " of the selected coordinates " + verb + " not a node (i.e. not defined with \\node but rather with \\draw or \\path)", true); curSel = null; return; // hack } */ //the return from above must not interfere with BeginModify() overlay.BeginUpdate(); // add an edge curSel to n //bool lcreated; //if (EnsureCurAddToExists(out lcreated)) //always create new \draw command. otherwise it can happen that the \draw-command //is above the \node-definition which causes an error while compiling the latex code. if (AddNewCurAddTo()) { // make sure both nodes involved have names Parser.Tikz_Node t1 = MakeReferenceableNode(curSel.tikzitem), t2 = MakeReferenceableNode(n.tikzitem); Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord(); tc1.type = Parser.Tikz_CoordType.Named; Parser.Tikz_Coord tc2 = new Parser.Tikz_Coord(); tc2.type = Parser.Tikz_CoordType.Named; curAddTo.AddChild(new Parser.Tikz_Something(" ")); curAddTo.AddChild(tc1); if (t1 == t2) curAddTo.AddChild(new Parser.Tikz_Something(" edge[loop, looseness=20] ")); else curAddTo.AddChild(new Parser.Tikz_Something(" edge ")); curAddTo.AddChild(tc2); //tpict.AddChild(tp); // make sure both nodes have names /* Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture(); if (t1.name == "") { t1.SetName(tpict.GetUniqueName()); t1.UpdateText(); } if (t2.name == "") { t2.SetName(tpict.GetUniqueName()); t2.UpdateText(); } */ tc1.nameref = t1.name; tc2.nameref = t2.name; //tc1.UpdateText(); curAddTo.UpdateText(); //tpict.UpdateText(); // txtCode_TextChanged //RedrawObjects(); //if (OnModified != null) // OnModified.Invoke(); //edge was drawn. release currently selected node. curSel = null; //will neither want to path tool to start from this last select nodes. curAddTo = null; } //forgetting to call EndModify causes weird "No undo group should be open at this point"-message. overlay.EndUpdate(); }
public override void OnDeactivate() { base.OnDeactivate(); curSel = null; }
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 } } */ } }
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); }
OverlayNodeView NewNodeView(OverlayNode on) { OverlayNodeView v = new OverlayNodeView(on); canvas1.Children.Add(v); return v; }
public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e) { if (!(item is OverlayNode)) { curSel = null; return; } OverlayNode n = item as OverlayNode; // make sure a referenceable item is selected... otherwise we cannot add an edge if (!IsReferenceable(item)) { GlobalUI.UI.AddStatusLine(this, "Only items that are referenceable (=can be given names) can be connected with the edge tool."); return; } if (curSel == null) { curSel = n; return; } // make sure both nodes involved are nodes /* if (!(curSel.tikzitem is Tikz_Node) || !(n.tikzitem is Tikz_Node)) * { * String which = ""; String verb = "is"; * if (!(curSel.tikzitem is Tikz_Node) && !(n.tikzitem is Tikz_Node)) * { which = "Both"; verb = "are"; } * else if (!(curSel.tikzitem is Tikz_Node)) * which = "The first"; * else if (!(n.tikzitem is Tikz_Node)) * which = "The second"; * MainWindow.AddStatusLine(which + " of the selected coordinates " + verb + " not a node (i.e. not defined with \\node but rather with \\draw or \\path)", true); * curSel = null; * return; // hack * } */ //the return from above must not interfere with BeginModify() overlay.BeginUpdate(); // add an edge curSel to n //bool lcreated; //if (EnsureCurAddToExists(out lcreated)) //always create new \draw command. otherwise it can happen that the \draw-command //is above the \node-definition which causes an error while compiling the latex code. if (AddNewCurAddTo()) { // make sure both nodes involved have names Parser.Tikz_Node t1 = MakeReferenceableNode(curSel.tikzitem), t2 = MakeReferenceableNode(n.tikzitem); Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord(); tc1.type = Parser.Tikz_CoordType.Named; Parser.Tikz_Coord tc2 = new Parser.Tikz_Coord(); tc2.type = Parser.Tikz_CoordType.Named; curAddTo.AddChild(new Parser.Tikz_Something(" ")); curAddTo.AddChild(tc1); if (t1 == t2) { curAddTo.AddChild(new Parser.Tikz_Something(" edge[loop, looseness=20] ")); } else { curAddTo.AddChild(new Parser.Tikz_Something(" edge ")); } curAddTo.AddChild(tc2); //tpict.AddChild(tp); // make sure both nodes have names /* Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture(); * if (t1.name == "") * { * t1.SetName(tpict.GetUniqueName()); * t1.UpdateText(); * } * if (t2.name == "") * { * t2.SetName(tpict.GetUniqueName()); * t2.UpdateText(); * } */ tc1.nameref = t1.name; tc2.nameref = t2.name; //tc1.UpdateText(); curAddTo.UpdateText(); //tpict.UpdateText(); // txtCode_TextChanged //RedrawObjects(); //if (OnModified != null) // OnModified.Invoke(); //edge was drawn. release currently selected node. curSel = null; //will neither want to path tool to start from this last select nodes. curAddTo = null; } //forgetting to call EndModify causes weird "No undo group should be open at this point"-message. overlay.EndUpdate(); }