public TracePane() { InitializeComponent(); traces = new List<Trace>(); elem = null; UpdateGUI(); }
public bool Query(Elem elem) { return(true); }
public void CalcElementDimensions(Elem elem) { if (elem.cache != null) return; Node node = elem.GetNode(); int decorationAdjustment = (node.Decoration.mode == DecorationMode.Node) ? (int)node.Decoration.padding : 0; int triangleAdjustment = (node.GetDisplayType() == NodeDisplayType.Triangle) ? (PaddingVertical() * 2 + MarginVertical()) : 0; if (node.IsBlank()) { /*this allows for drawing of the big red x; see PaintElement*/ elem.Dimensions = new Size(20, 20); elem.Dimensions_label = elem.Dimensions_lex = Size.Empty; } else if (node.HasLexical() && node.HasLabel()) { m_richtext.Reset(); m_richtext.ZoomFactor = GetZoomFactor(); m_richtext.Rtf = node.GetLabelRtf(); m_richtext.FixupComponentLabel(); elem.Dimensions_label = EstimateSpace(m_richtext); m_richtext.Reset(); m_richtext.ZoomFactor = GetZoomFactor(); m_richtext.Rtf = node.GetLexicalRtf(); m_richtext.FixupComponentLexical(); elem.Dimensions_lex = EstimateSpace(m_richtext); elem.Dimensions = new Size(Math.Max(elem.Dimensions_lex.Width, elem.Dimensions_label.Width), elem.Dimensions_lex.Height + elem.Dimensions_label.Height); } else if (node.HasLabel()) { m_richtext.Reset(); m_richtext.ZoomFactor = GetZoomFactor(); m_richtext.Rtf = node.GetLabelRtf(); m_richtext.FixupComponentLabel(); elem.Dimensions = elem.Dimensions_label = EstimateSpace(m_richtext); elem.Dimensions_lex = Size.Empty; } else if (node.HasLexical()) { m_richtext.Reset(); m_richtext.ZoomFactor = GetZoomFactor(); m_richtext.Rtf = node.GetLexicalRtf(); m_richtext.FixupComponentLexical(); elem.Dimensions = elem.Dimensions_lex = EstimateSpace(m_richtext); elem.Dimensions_label = Size.Empty; } elem.Dimensions = new Size(elem.Dimensions.Width + PaddingHorizontal() + decorationAdjustment, elem.Dimensions.Height + PaddingVertical() + decorationAdjustment + triangleAdjustment); }
public FormatChanges GetFormatElement(Elem elem, bool lexical) { Node node = elem.GetNode(); Dummy richtext = Dummy.GetInstance(); richtext.Reset(); richtext.Rtf = lexical ? node.GetLexicalRtf() : node.GetLabelRtf(); richtext.SelectAll(); return richtext.GetFormatChanges(); }
public Point[] GetPoints(Elem e, int traceHSpacing, int traceVSpacing, int traceCount) { ElemTrace elemtrace = this; int soffset = (-(elemtrace.source.tracecount - 1) / 2 + elemtrace.sourcexth) * traceHSpacing; int doffset = (-(elemtrace.destination.tracecount - 1) / 2 + elemtrace.destinationxth) * traceHSpacing; const int paddingv = 0; int depth; bool drop = true; bool reverse = false; if (longextent) depth = e.Location.Y + e.BranchDimensions.Height; else depth = Math.Max(elemtrace.destination.Rect.Bottom, elemtrace.source.Rect.Bottom); //wot a mess Point start; int whereto = elemtrace.destination.Rect.Left + elemtrace.destination.Rect.Width / 2 + doffset; if (elemtrace.source.Location.Y + elemtrace.source.Rect.Height / 2 > elemtrace.destination.Rect.Bottom && elemtrace.source.NumChildren() > 0 && elemtrace.sourcexth == 0 && (whereto < elemtrace.source.Rect.Left || whereto > elemtrace.source.Rect.Right)) { if (whereto < elemtrace.source.Rect.Left) start = new Point(elemtrace.source.Rect.Left - paddingv, elemtrace.source.Rect.Top + elemtrace.source.Rect.Height / 2); else start = new Point(elemtrace.source.Rect.Right + paddingv, elemtrace.source.Rect.Top + elemtrace.source.Rect.Height / 2); drop = false; } else start = new Point(elemtrace.source.Rect.Left + elemtrace.source.Rect.Width / 2 + soffset, elemtrace.source.Rect.Bottom + paddingv); Point end; whereto = elemtrace.source.Rect.Left + elemtrace.source.Rect.Width / 2 + soffset; if (elemtrace.destination.Location.Y + elemtrace.destination.Rect.Height / 2 > elemtrace.source.Rect.Bottom && elemtrace.destination.NumChildren() > 0 && elemtrace.destinationxth == 0 && (whereto < elemtrace.destination.Rect.Left || whereto > elemtrace.destination.Rect.Right)) { if (whereto < elemtrace.destination.Rect.Left) end = new Point(elemtrace.destination.Rect.Left - paddingv, elemtrace.destination.Rect.Top + elemtrace.destination.Rect.Height / 2); else end = new Point(elemtrace.destination.Rect.Right + paddingv, elemtrace.destination.Rect.Top + elemtrace.destination.Rect.Height / 2); drop = false; reverse = true; } else end = new Point(elemtrace.destination.Rect.Left + elemtrace.destination.Rect.Width / 2 + doffset, elemtrace.destination.Rect.Bottom + paddingv); Point[] points; if (drop) points = new Point[] { start, new Point(start.X, depth+traceCount*traceVSpacing), new Point(end.X, depth+traceCount*traceVSpacing), end }; else points = new Point[] { start, reverse?new Point(start.X,end.Y):new Point(end.X,start.Y), end }; return points; }
public bool HasTrace(Elem a, Elem b) { foreach (ElemTrace et in Traces()) if ((et.source == a && et.destination == b) || (et.source == b && et.destination == a)) return true; return false; }
public void Invoke(Elem elem) { stv.DoCreateTrace(stv.m_selected[0], elem, true); }
private Elem WlkRightmostChild(Elem e) { //this can be made much more efficient with direct acess to Node::m_children Elem rm = null; foreach (Elem elem in e.Children()) { rm = elem; } return rm; }
private void WlkExecuteShifts(Elem v) { int shift = 0; int change = 0; List<Elem> reverse = new List<Elem>(v.NumChildren()); foreach (Elem e in v.Children()) /*and this monstrosity. ug!*/ reverse.Add(e); reverse.Reverse(); foreach (Elem w in reverse) { w.prelim = w.prelim + shift; w.mod = w.mod + shift; change = change + w.change; shift = shift + w.shift + change; } }
private void WlkApportion(Elem v, Elem defaultAncestor) { Elem w = WlkGetLeftSibling(v); Elem viplus, voplus, viminus, vominus; if (w != null) { int siplus, soplus, siminus, sominus; viplus = voplus = v; viminus = w; vominus = WlkGetLeftMostSibling(viplus); siplus = viplus.mod; soplus = voplus.mod; siminus = viminus.mod; sominus = vominus.mod; while (WlkNextRight(viminus) != null && WlkNextLeft(viplus) != null) { viminus = WlkNextRight(viminus); viplus = WlkNextLeft(viplus); vominus = WlkNextLeft(vominus); voplus = WlkNextRight(voplus); voplus.ancestor = v; int shift = (viminus.prelim + siminus) - (viplus.prelim + siplus) + viminus.Dimensions.Width + MarginHorizontal(); if (shift > 0) { WlkMoveSubtree(WlkAncestor(viminus, v, defaultAncestor), v, shift); siplus = siplus + shift; soplus = soplus + shift; } siminus = siminus + viminus.mod; siplus = siplus + viplus.mod; sominus = sominus + vominus.mod; soplus = soplus + voplus.mod; } if (WlkNextRight(viminus) != null && WlkNextRight(voplus) == null) { voplus.thread = WlkNextRight(viminus); voplus.mod = voplus.mod + siminus - soplus; } if (WlkNextLeft(viplus) != null && WlkNextLeft(vominus) == null) { vominus.thread = WlkNextLeft(viplus); vominus.mod = vominus.mod + siplus - sominus; defaultAncestor = v; } } }
private Elem WlkAncestor(Elem viminus, Elem v, Elem defaultAncestor) { if (viminus.ancestor.Parent == v.Parent && viminus.ancestor != v) return viminus.ancestor; else return defaultAncestor; }
private void UpdateTreeData() { m_height = 0; bool somethingSelected = false; if (m_selected == null) m_selected = new List<Elem>(); else { if (m_selected.Count > 0) somethingSelected = true; m_selected.Clear(); } if (m_elemByLevel == null) m_elemByLevel = new List<List<Elem>>(); else m_elemByLevel.Clear(); if (m_elemRoot != null) { m_elemRoot.Dispose(); m_elemRoot = null; } m_elemRoot = ScanWorker(m_syntax.Root, m_elemByLevel, 1); m_levelDimensions = new Size[m_height]; for (int i = 0; i < m_height; i++) m_levelDimensions[i] = GetLevelDimensions(i); UpdateTraces(); OptTreeDraw1(m_elemRoot); if (somethingSelected) FireSelectionChange(); }
public void Add(Elem elem) { m_children.Add(elem); elem.m_parent = this; }
private void UpdateTracesWorker(Elem elem) { //elem.m_traces.Clear() Node node = elem.GetNode(); if (node.NumTraces() > 0) { foreach (Trace trace in node.Traces()) { if (trace.source == node) { foreach (Elem possibledest in Elements()) { if (trace.destination == possibledest.GetNode()) { ElemTrace newtrace = new ElemTrace(elem, possibledest, trace); InitElemTrace(newtrace); newtrace.sourcexth = elem.tracecount++; newtrace.destinationxth = possibledest.tracecount++; newtrace.ancestor.Add(newtrace); goto foo; } } throw new TreeException("Unfound destination"); } foo: ; } } }
private void UpdateTraces(Elem elem) { foreach (Elem e in elem.Children()) UpdateTraces(e); UpdateTracesWorker(elem); }
private Point StdCalcPlacement(Elem e, Point relativeTo, Size totalSize) { Point placement = new Point( relativeTo.X - totalSize.Width / 2 + e.BranchDimensions.Width / 2 + e.indent - e.Dimensions.Width / 2, e.vindent + relativeTo.Y); return placement; }
private Elem WlkNextRight(Elem v) { if (v.NumChildren() > 0) return WlkRightmostChild(v); else return v.thread; }
private void WlkFindExtents(Elem node, int m, int depth, ref int max, ref int min) { int thismin = m + node.prelim; int thismax = m + node.prelim + node.Dimensions.Width; int maxheight = 0; foreach (Elem elem in node.Children()) { int localmin = 0, localmax = 0; WlkFindExtents(elem, node.mod + m, depth + 1, ref localmax, ref localmin); thismin = Math.Min(thismin, localmin); thismax = Math.Max(thismax, localmax); maxheight = Math.Max(maxheight, elem.BranchDimensions.Height); } if (maxheight == 0) maxheight = m_levelDimensions[depth].Height; else maxheight += m_levelDimensions[depth].Height + MarginVertical(); max = thismax; min = thismin; node.shift = min; node.BranchDimensions = new Size(max - min, maxheight); }
private void WlkSecondWalk(Elem v, int m, int level, Point origin) { int myy = v.Parent == null ? origin.Y : v.Parent.Location.Y + m_levelDimensions[level - 1].Height + MarginVertical(); v.Location = new Point(v.prelim + m + origin.X, myy); foreach (Elem w in v.Children()) WlkSecondWalk(w, m + v.mod, level + 1, origin); }
private void WlkFirstWalk(Elem v) { if (v.NumChildren() == 0) { v.prelim = 0; Elem left = WlkGetLeftSibling(v); if (left != null) v.prelim = left.prelim + MarginHorizontal() + left.Dimensions.Width; } else { Elem leftmostChild = WlkLeftmostChild(v); Elem rightmostChild = WlkRightmostChild(v); Elem defaultAncestor = leftmostChild; foreach (Elem w1 in v.Children()) { WlkFirstWalk(w1); WlkApportion(w1, defaultAncestor); } WlkExecuteShifts(v); int midpoint = (leftmostChild.prelim + leftmostChild.Dimensions.Width / 2 + rightmostChild.prelim + rightmostChild.Dimensions.Width / 2) - v.Dimensions.Width; midpoint /= 2; Elem w = WlkGetLeftSibling(v); if (w != null) { v.prelim = w.prelim + MarginHorizontal() + w.Dimensions.Width; v.mod = v.prelim - midpoint; } else v.prelim = midpoint; } }
public bool Query(Elem elem) { return stv.DoCreateTrace(stv.m_selected[0], elem, false); }
private Elem WlkGetLeftMostSibling(Elem e) { /*optimize this too*/ if (e.Parent != null) foreach (Elem elem in e.Parent.Children()) return elem; return null; }
public ElemTrace(Elem source, Elem destination, Trace trace) { this.source = source; this.destination = destination; this.trace = trace; sourcexth = destinationxth = 0; longextent = false; ancestor = null; }
public void Dispose() { FreeCache(); foreach (Elem elem in Children()) elem.Dispose(); thread = ancestor = m_parent = null; m_children = null; m_traces = null; }
public Rectangle GetRectangle(Elem e, int traceHSpacing, int traceVSpacing, int traceCount) { Point[] points = GetPoints(e, traceHSpacing, traceVSpacing, traceCount); Rectangle ret = new Rectangle(points[0], Size.Empty); for (int i = 1; i < points.Length; i++) ret = Rectangle.Union(ret, new Rectangle(points[i], Size.Empty)); return ret; }
private Elem WlkGetLeftSibling(Elem e) { /*and this*/ if (e.Parent != null) { Elem last = null; foreach (Elem elem in e.Parent.Children()) { if (elem == e) break; last = elem; } return last; } return null; }
public void ReformatElement(Elem elem, bool lexical, FormatChanges fc) { Node node = elem.GetNode(); Dummy richtext = Dummy.GetInstance(); richtext.Reset(); richtext.Rtf = lexical ? node.GetLexicalRtf() : node.GetLabelRtf(); richtext.SelectAll(); richtext.SetFormatChanges(fc); if (lexical) node.SetLexicalRtfAndText(richtext.Rtf, richtext.Text); else node.SetLabelRtfAndText(richtext.Rtf, richtext.Text); elem.FreeCache(); }
private Elem WlkGetRightSibling(Elem e) { /*and this*/ if (e.Parent != null) { bool last = false; foreach (Elem elem in e.Parent.Children()) { if (last) return elem; if (elem == e) last = true; } } return null; }
public void Invoke(Elem elem) { }
private Elem WlkLeftmostChild(Elem e) { //this can be made much more efficient with direct acess to Node::m_children foreach (Elem elem in e.Children()) { return elem; } return null; }
private void WlkMoveSubtree(Elem wminus, Elem wplus, int shift) { int subtrees = wplus.GetNumber() - wminus.GetNumber() - 1; if (subtrees < 1) subtrees = 1; wplus.change = wplus.change - shift / subtrees; wplus.shift = wplus.shift + shift; wminus.change = wminus.change + shift / subtrees; wplus.prelim = wplus.prelim + shift; wplus.mod = wplus.mod + shift; }
private void StdCalcBranchDimensions(Elem elem) { CalcBranchDimensions(elem, 0); }