Beispiel #1
0
        public void ItemSelectNodeActions()
        {
            /*todo: allow multi-delete?*/
            bool enable = m_selected.Count == 1;

            if (enable)
            {
                Elem elem = m_selected[0];
                createChildButton.Enabled = elem.GetNode().CanAddChildHere();
                deleteButton.Enabled      = elem.GetNode().CanBeDeleted();
            }
            nodeOperationsGroupBox.Enabled = enable;
        }
Beispiel #2
0
 private void deleteTraceToolStripButton_Click(object sender, EventArgs e)
 {
     if (elem != null)
     {
         stv.UndoAdd();
         Trace o = traceListBox.SelectedItem as Trace;
         if (o != null)
         {
             elem.GetNode().RemoveTrace(o);
         }
         FireTraceModified();
     }
 }
Beispiel #3
0
 private void labelEditRichEditBox_TextChanged(object sender, EventArgs e)
 {
     if (!updating)
     {
         if (m_selected.Count == 1 && labelEditRichEditBox.Enabled)
         {
             Elem elem = m_selected[0];
             Node node = elem.GetNode();
             elem.FreeCache();
             string labelRtf  = labelEditRichEditBox.Rtf;
             string labelText = labelEditRichEditBox.Text;
             if (labelEditRichEditBox.Modified && node.GetLabelRtf() != labelRtf)
             {
                 SelectivelyAddUndo();
                 node.SetLabelRtfAndText(labelEditRichEditBox.Rtf, labelEditRichEditBox.Text);
                 tracePane.RefreshData();
                 m_stv.UpdateEverything(true);
             }
         }
     }
 }
Beispiel #4
0
        public void SetTraces(Elem elem)
        {
            this.elem = elem;
            if (elem == null)
            {
                traceListBox.DataSource = null;
                return;
            }
            Node node = elem.GetNode();

            traces.Clear();
            traceListBox.DataSource = null;
            foreach (Trace t in node.Traces())
            {
                traces.Add(t);
            }
            traceListBox.DataSource = traces;
            if (traceListBox.Items.Count > 0)
            {
                traceListBox.SelectedIndex = 0;
            }
        }
Beispiel #5
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);
        }
Beispiel #6
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();
        }
Beispiel #7
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();
 }
Beispiel #8
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: ;
                }
            }
        }
Beispiel #9
0
        private RenderNodePositionInfo RenderNode(GraphicsProxy g, Elem elem, Rectangle where, bool isSelected, bool generatePosInfo)
        {
            Node node = elem.GetNode();

            int labelheight = node.HasLabel() ? elem.Dimensions_label.Height : 0;
            int lexheight = node.HasLexical() ? elem.Dimensions_lex.Height : 0;
            int paddingvertical = PaddingVertical();

            int sumheight = labelheight + lexheight +
                ((node.GetDisplayType() == NodeDisplayType.Triangle) ? (paddingvertical * 2 + MarginVertical()) : 0);

            if (sumheight > 0)
            {
                Rectangle labelRect = new Rectangle(where.Left + (where.Width / 2) - (elem.Dimensions_label.Width / 2),
                        where.Top + where.Height / 2 - sumheight / 2,
                        elem.Dimensions_label.Width, elem.Dimensions_label.Height);
                Rectangle lexRect = new Rectangle(where.Left + where.Width / 2 - elem.Dimensions_lex.Width / 2,
                        where.Bottom - where.Height / 2 + sumheight / 2 - lexheight,
                        elem.Dimensions_lex.Width, elem.Dimensions_lex.Height);

                if (node.HasLabel())
                {
                    m_richtext.Reset();
                    m_richtext.ZoomFactor = GetZoomFactor();
                    m_richtext.Rtf = node.GetLabelRtf();

                    //m_richtext.Text = elem.altitude.ToString();//!!
                    m_richtext.FixupComponentLabel(isSelected ? HighlightBackColor() : StandardBackColor());

                    g.RenderRTF(m_richtext, labelRect.Left, labelRect.Top, labelRect.Width, labelRect.Height);
                }
                if (node.HasLexical())
                {
                    m_richtext.Reset();
                    m_richtext.ZoomFactor = GetZoomFactor();
                    m_richtext.Rtf = node.GetLexicalRtf();
                    m_richtext.FixupComponentLexical(isSelected ? HighlightBackColor() : StandardBackColor());
                    g.RenderRTF(m_richtext, lexRect.Left, lexRect.Top, lexRect.Width, lexRect.Height);
                }
                if (generatePosInfo)
                    return new RenderNodePositionInfo(labelRect, lexRect);
                else
                    return null;
            }
            return null;
        }
Beispiel #10
0
        private void PaintElement(GraphicsProxy g, Elem e)
        {
            Node node = e.GetNode();
            Point placement = e.Location;
            bool isSelected = m_selected.Contains(e);

            if (e.Parent != null)
                g.DrawLine(StandardLinePen(), placement.X + e.Dimensions.Width / 2, placement.Y,
                    e.Parent.Location.X + e.Parent.Dimensions.Width / 2, e.Parent.Location.Y +
                    e.Parent.Dimensions.Height);

            if (node.IsBlank())
            {
                if (isSelected)
                    g.FillRectangle(HighlightBackBrush(), placement.X, placement.Y, e.Dimensions.Width - 1,
                        e.Dimensions.Height - 1);
                /*the minus 1 in the above line prevent a weird screen artefact when drawing
                 the selected variant of the red X when antialiasing is on. It looks like
                 the antialiasing actually draws pixels outside the box specified? One solution
                 would be to push antialias state, turn it off, draw the box, and pop antialias state,
                 but this is faster and adequate*/
                DrawBigX(g, placement.X + (e.Dimensions.Width / 2), placement.Y + (e.Dimensions.Height / 2));
            }
            else
            {
                Graphics realGraphics = g.Graphics;
                if (realGraphics == null)
                    RenderNode(g, e, e.Rect, isSelected, false);
                else
                {
                    if (e.cache == null)
                    {
                        Bitmap bm = new Bitmap(e.Dimensions.Width, e.Dimensions.Height);
                        using (Graphics bmGraphics = Graphics.FromImage(bm))
                        {
                            GraphicsPassThrough gp = new GraphicsPassThrough(bmGraphics);
                            SetupAntiAliasing(gp);
                            RenderNodePositionInfo rnpi =
                                RenderNode(gp, e, new Rectangle(Point.Empty, e.Dimensions), false, true);
                            e.labelRect = rnpi.labelRect;
                            e.lexRect = rnpi.lexRect;
                        }
                        e.cache = bm;
                        bm = new Bitmap(e.Dimensions.Width, e.Dimensions.Height);
                        using (Graphics bmGraphics = Graphics.FromImage(bm))
                        {
                            GraphicsPassThrough gp = new GraphicsPassThrough(bmGraphics);
                            SetupAntiAliasing(gp);
                            RenderNode(gp, e, new Rectangle(Point.Empty, e.Dimensions), true, false);
                        }
                        e.cacheSelected = bm;
                    }
                    realGraphics.DrawImageUnscaled(isSelected ? e.cacheSelected : e.cache, e.Location);

                    /*
                     * I would like to draw the image with transparency, but this
                     * produces problems since the text image includes gradients
                     * resulting from text antialiasing
                    System.Drawing.Imaging.ImageAttributes attrs=
                        new System.Drawing.Imaging.ImageAttributes();
                    attrs.SetColorKey(Color.White, Color.White);
                    realGraphics.DrawImage(isSelected ? e.cacheSelected : e.cache,
                        e.Rect, 0, 0, e.Rect.Width, e.Rect.Height, GraphicsUnit.Pixel,
                        attrs);
                     */
                }

                if (node.GetDisplayType() == NodeDisplayType.Triangle)
                {
                    int paddingvertical = PaddingVertical();
                    Rectangle lexRect = e.lexRect;
                    Rectangle labelRect = e.labelRect;
                    lexRect.Offset(e.Location);
                    labelRect.Offset(e.Location);
                    g.DrawPolygon(StandardLinePen(), new Point[] {
                    new Point(lexRect.Left,lexRect.Top-paddingvertical),
                    new Point(lexRect.Right,lexRect.Top-paddingvertical),
                    new Point(labelRect.Left+labelRect.Width/2,labelRect.Bottom+paddingvertical)
                });
                }
            }

            Decoration decoration = node.Decoration;
            if (decoration.mode != DecorationMode.None)
            {
                int pv = PaddingVertical() / 2 + (int)node.Decoration.penstyle.width;
                int ph = PaddingHorizontal() / 2 + (int)node.Decoration.penstyle.width;
                int pd = node.Decoration.padding;
                Rectangle decorationRect;
                if (decoration.mode == DecorationMode.Node)
                    decorationRect = new Rectangle(e.Rect.Left + ph, e.Rect.Top + pv, e.Rect.Width - ph * 2, e.Rect.Height - pv * 2);
                else
                { // subtree mode
                    decorationRect = OptGetSubTreeRectangle(e);
                    decorationRect.Inflate(pd, pd);
                }
                switch (decoration.shape)
                {
                    case DecorationShape.Ellipse:
                        using (Pen pen = decoration.penstyle.GetPen(GetZoomFactor()))
                            g.DrawEllipse(pen, decorationRect.Left, decorationRect.Top, decorationRect.Width, decorationRect.Height);
                        break;
                    case DecorationShape.Cross:
                        using (Pen pen = decoration.penstyle.GetPen(GetZoomFactor()))
                        {
                            g.DrawLine(pen, decorationRect.Left, decorationRect.Top, decorationRect.Left + decorationRect.Width, decorationRect.Height + decorationRect.Top);
                            g.DrawLine(pen, decorationRect.Left, decorationRect.Top + decorationRect.Height, decorationRect.Left + decorationRect.Width, decorationRect.Top);
                        }
                        break;
                    case DecorationShape.Rectangle:
                        using (Pen pen = decoration.penstyle.GetPen(GetZoomFactor()))
                            g.DrawRectangle(pen, decorationRect.Left, decorationRect.Top, decorationRect.Width, decorationRect.Height);
                        break;
                    default:
                        throw new Exception("unknown shape");
                }
            }

            /*in determining how to vertically space traces,
             we should perhaps use a fancier algorithm, so that their
             height is offset only if they would actually cross. An reasonable
             approximation of such a fancy algorithm might keep track of
             traceCount on a per-level basis, rather than a per-common-ancestor
             basis

             * This block, which draws the traces, shouldn't be here,
             * as traces shouldn't be members of elements
             */
            int traceCount = 0;
            foreach (ElemTrace elemtrace in e.Traces())
            {
                traceCount++;
                using (Pen pen = elemtrace.trace.penstyle.GetPen(GetZoomFactor()))
                {

                    Point[] points = elemtrace.GetPoints(e, TraceSpacingHorizontal(),
                        TraceSpacingVertical(), traceCount);
                    switch (elemtrace.trace.tracestyle)
                    {
                        case TraceStyle.Line:
                            g.DrawLines(pen, points);
                            break;
                        case TraceStyle.Curve:
                            g.DrawBezier(pen, points[0], points[1], points[points.Length - 2], points[points.Length - 1]);
                            break;
                        default:
                            throw new TreeException("Unknown trace style");
                    }
                }
            }
        }
Beispiel #11
0
        void ExtendMaximumExtents(Elem elem)
        {
            Decoration dec = elem.GetNode().Decoration;
            if (dec.mode == DecorationMode.Subtree)
            {
                Rectangle decorationRect = OptGetSubTreeRectangle(elem);
                decorationRect.Inflate(dec.padding + (int)dec.penstyle.width,
                    dec.padding + (int)dec.penstyle.width);
                m_maximumExtents = Rectangle.Union(m_maximumExtents, decorationRect);
            }

            foreach (ElemTrace elemtrace in elem.Traces())
            {
                Rectangle r = elemtrace.GetRectangle(elem, TraceSpacingHorizontal(),
                    TraceSpacingVertical(), elem.NumTraces());
                r.Inflate((int)elemtrace.trace.penstyle.width, (int)elemtrace.trace.penstyle.width);
                m_maximumExtents = Rectangle.Union(m_maximumExtents,
                    r);

            }
        }
Beispiel #12
0
        private bool DoDraggedTo(Elem to, Elem from, bool forReal)
        {
            bool changed = false;
            if (to == from)
            {
                //can't do that
            }
            else if (to.Parent == from.Parent)
            {
                if (forReal)
                {
                    Node parent = to.Parent.GetNode();
                    int ito = parent.FindChild(to.GetNode());
                    int ifrom = parent.FindChild(from.GetNode());
                    parent.SwapChildren(ito, ifrom);
                }

                changed = true;
            }
            else if (to == from.Parent || from == to.Parent)
            {
                if (from == to.Parent)
                {
                    Elem temp = to;
                    to = from;
                    from = temp;
                }
                if (from.GetNode().CanAddChildHere())
                {
                    if (forReal)
                    {
                        int where = to.GetNode().FindChild(from.GetNode());
                        to.GetNode().SwapWithChild(where);
                    }
                    changed = true;
                }
            }
            else if (from.GetNode().IsAncestorOf(to.GetNode()))
            {
                if (from.GetNode().NumChildren() == 1)
                {
                    if (from.Parent == null)
                    {
                        if (forReal)
                        {
                            Node newroot = from.GetNode().FindChild(0);
                            from.GetNode().Detach(0);
                            to.GetNode().Attach(from.GetNode());
                            m_syntax.Root = newroot;
                        }
                        changed = true;
                    }
                    else
                    {
                        if (forReal)
                        {
                            int ff = from.Parent.GetNode().FindChild(from.GetNode());
                            from.Parent.GetNode().DetachAndReplaceWithChild(ff);
                            to.GetNode().Attach(from.GetNode());
                        }
                        changed = true;
                    }
                }
            }
            else
            {
                Node nto = to.GetNode();
                Node nfrom = from.GetNode();
                if (nto.CanAddChildHere() && from.Parent.GetNode() != null)
                {
                    if (forReal)
                    {
                        int ifrom = from.Parent.GetNode().FindChild(nfrom);
                        from.Parent.GetNode().Detach(ifrom);

                        nto.Attach(nfrom);
                    }
                    changed = true;
                }
            }
            if (changed && forReal)
                UpdateEverything(false);
            return changed;
        }
Beispiel #13
0
 void CalcNodeInfoRecurse(Elem elem, int current, int target)
 {
     int nchildren = elem.GetNode().NumChildren();
     elem.BranchDimensions = new Size(target, elem.BranchDimensions.Height);
     if (nchildren == 0)
         return;
     int delta = target - current;
     int target_delta = delta / nchildren;
     foreach (Elem child in elem.Children())
     {
         int child_width = child.BranchDimensions.Width;
         CalcNodeInfoRecurse(child, child_width, child_width + target_delta);
     }
 }
Beispiel #14
0
 private void CalcBranchDimensions(Elem elem, int depth)
 {
     Node n = elem.GetNode();
     if (!n.HasChildren())
         elem.BranchDimensions = elem.Dimensions;
     else
     {
         int wsum = 0; int hmax = 0; int wmax = 0;
         foreach (Elem child in elem.Children())
         {
             CalcBranchDimensions(child, depth + 1);
             wmax = Math.Max(wmax, child.BranchDimensions.Width);
             hmax = Math.Max(hmax, child.BranchDimensions.Height);
             wsum += MarginHorizontal() + child.BranchDimensions.Width;
         }
         if (RowsArranged())
             hmax += m_levelDimensions[depth].Height + MarginVertical();
         else
             hmax += elem.Dimensions.Height + MarginVertical();
         wsum -= MarginHorizontal();
         if (ShouldDoBalancedTree())
         {
             foreach (Elem child in elem.Children())
             {
                 if (wmax > child.BranchDimensions.Width)
                     CalcNodeInfoRecurse(child, child.BranchDimensions.Width, wmax);
                 child.BranchDimensions = new Size(wmax, child.BranchDimensions.Height);
             }
             wsum = (elem.GetNode().NumChildren()) *
                 wmax + (MarginHorizontal() * (elem.GetNode().NumChildren() - 1));
         }
         if (wsum < elem.Dimensions.Width)
         {
             CalcNodeInfoRecurse(elem, wsum, elem.Dimensions.Width);
             wsum = elem.Dimensions.Width;
         }
         elem.BranchDimensions = new Size(wsum, hmax);
     }
 }
Beispiel #15
0
 public bool DoCreateTrace(Elem source, Elem dest, bool forReal)
 {
     bool done = false;
     if (source != dest)
     {
         if (!FindCommonAncestor(source, dest).HasTrace(source, dest))
         {
             if (forReal)
             {
                 UndoAdd();
                 source.GetNode().AddTraceFromHere(dest.GetNode());
                 UpdateEverything(false); //use a less comprehensive update here
             }
             done = true;
         }
     }
     return done;
 }