Exemplo n.º 1
0
 public TracePane()
 {
     InitializeComponent();
     traces = new List<Trace>();
     elem = null;
     UpdateGUI();
 }
Exemplo n.º 2
0
 public bool Query(Elem elem)
 {
     return(true);
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 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();
 }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
 public void Invoke(Elem elem)
 {
     stv.DoCreateTrace(stv.m_selected[0], elem, true);
 }
Exemplo n.º 8
0
 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;
 }
Exemplo n.º 9
0
 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;
     }
 }
Exemplo n.º 10
0
        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;
                }
            }
        }
Exemplo n.º 11
0
 private Elem WlkAncestor(Elem viminus, Elem v, Elem defaultAncestor)
 {
     if (viminus.ancestor.Parent == v.Parent && viminus.ancestor != v)
         return viminus.ancestor;
     else return defaultAncestor;
 }
Exemplo n.º 12
0
        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();
        }
Exemplo n.º 13
0
 public void Add(Elem elem)
 {
     m_children.Add(elem);
     elem.m_parent = this;
 }
Exemplo n.º 14
0
        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: ;
                }
            }
        }
Exemplo n.º 15
0
 private void UpdateTraces(Elem elem)
 {
     foreach (Elem e in elem.Children())
         UpdateTraces(e);
     UpdateTracesWorker(elem);
 }
Exemplo n.º 16
0
 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;
 }
Exemplo n.º 17
0
 private Elem WlkNextRight(Elem v)
 {
     if (v.NumChildren() > 0)
         return WlkRightmostChild(v);
     else
         return v.thread;
 }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 20
0
        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;

            }
        }
Exemplo n.º 21
0
 public bool Query(Elem elem)
 {
     return stv.DoCreateTrace(stv.m_selected[0], elem, false);
 }
Exemplo n.º 22
0
 private Elem WlkGetLeftMostSibling(Elem e)
 {
     /*optimize this too*/
     if (e.Parent != null)
         foreach (Elem elem in e.Parent.Children())
             return elem;
     return null;
 }
Exemplo n.º 23
0
 public ElemTrace(Elem source, Elem destination, Trace trace)
 {
     this.source = source;
     this.destination = destination;
     this.trace = trace;
     sourcexth = destinationxth = 0;
     longextent = false; ancestor = null;
 }
Exemplo n.º 24
0
 public void Dispose()
 {
     FreeCache();
     foreach (Elem elem in Children())
         elem.Dispose();
     thread = ancestor = m_parent = null;
     m_children = null;
     m_traces = null;
 }
Exemplo n.º 25
0
 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;
 }
Exemplo n.º 26
0
 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;
 }
Exemplo n.º 27
0
        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();
        }
Exemplo n.º 28
0
 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;
 }
Exemplo n.º 29
0
 public void Invoke(Elem elem)
 {
 }
Exemplo n.º 30
0
 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;
 }
Exemplo n.º 31
0
        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;
        }
Exemplo n.º 32
0
 private void StdCalcBranchDimensions(Elem elem)
 {
     CalcBranchDimensions(elem, 0);
 }