public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e) { if (!EnsureParseTreeExists()) { return; } overlay.BeginUpdate(); overlay.SetCorrectRaster(overlay.CurEditing, true); //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y); p = overlay.Rasterizer.RasterizePixelToTikz(p); if (ContinueWithBigImage(p) == false) { return; } // find next tikzpicture and add Parser.Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture(); if (tpict != null) { Parser.Tikz_Node tn = new Parser.Tikz_Node(); tn.label = ""; tn.coord = new Parser.Tikz_Coord(); if (overlay.NodeStyle != "") { tn.options = "[" + overlay.NodeStyle + "]"; } Parser.Tikz_Path tp = new Parser.Tikz_Path(); tp.starttag = @"\node "; tp.endtag = ";"; tp.AddChild(tn); 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")); } // do it here since the coordinate calculation needs the parents' coord. transform tn.SetAbsPos(new Point(p.X, p.Y)); //hack //tn.UpdateText(); tp.UpdateText(); //tpict.UpdateText(); //RedrawObjects(); overlay.AddToDisplayTree(tp); } overlay.EndUpdate(); }
public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e) { if (!EnsureParseTreeExists()) return; overlay.BeginUpdate(); overlay.SetCorrectRaster(overlay.CurEditing, true); //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y); p = overlay.Rasterizer.RasterizePixelToTikz(p); if (ContinueWithBigImage(p) == false) return; // find next tikzpicture and add Parser.Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture(); if (tpict != null) { Parser.Tikz_Node tn = new Parser.Tikz_Node(); tn.label = ""; tn.coord = new Parser.Tikz_Coord(); if (!String.IsNullOrEmpty(overlay.NodeStyle)) tn.options = "[" + overlay.NodeStyle + "]"; Parser.Tikz_Path tp = new Parser.Tikz_Path(); tp.starttag = @"\node "; tp.endtag = ";"; tp.AddChild(tn); 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")); } // do it here since the coordinate calculation needs the parents' coord. transform tn.SetAbsPos(new Point(p.X, p.Y)); //hack //tn.UpdateText(); tp.UpdateText(); //tpict.UpdateText(); //RedrawObjects(); // overlay.AddToDisplayTree(tp); } overlay.EndUpdate(); }
public override void OnLeftMouseButtonDown(OverlayShape 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)) { MainWindow.AddStatusLine("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(); }