Esempio n. 1
0
    public void Render()
    {
        items = new List<CanvasItem>();
        lifeLines = new List<LifeLine>();
        Dictionary<string, LifeLine> llDict = new Dictionary<string, LifeLine>();
        double x_where = 50.5;
        double y_step = 25;
        y_current = 0;

        width = 0;
        height = 0;

        foreach(ElemObj elem in diagram.elements)
        {
            TextBox tb = new TextBox();
            tb.YTop = 10.5;
            tb.XCenter = x_where;
            x_where += 100;
            width += 100;
            tb.Width = 70;
            tb.BorderWidth = 3;
            tb.Text = elem.text;

            tb.Layout(cr);
            items.Add(tb);
            LifeLine ll = new LifeLine(elem.label, this, tb.XCenter, tb.Y1);
            lifeLines.Add(ll);
            llDict.Add(elem.label, ll);
            if(tb.Y1 > YCurrent)
            {
                YCurrent = tb.Y1;
            }
        }

        foreach(Step step in diagram.sequence)
        {
            if(step.amount == 0)
            {
                step.amount = (int)y_step;
            }

            YCurrent += step.amount;

            foreach(LifeLine ll in lifeLines)
            {
                ll.BeforeActivations();
            }

            foreach(Activation a in step.activations)
            {
                LifeLine ll = llDict[a.label];

                if(a.on)
                {
                    ll.Activate();
                }
                else
                {
                    ll.Deactivate();
                }
            }

            foreach(LifeLine ll in lifeLines)
            {
                ll.AfterActivations();
            }

            foreach(Arrow arrow in step.arrows)
            {
                TextArrow ta;
                LifeLine to = llDict[arrow.to];
                LifeLine from = llDict[arrow.from];

                if(to != from)
                {
                    ta = new TextArrow();
                    bool right = to.X > from.X;
                    ta.Y0 = YCurrent;
                    if(right)
                    {
                        ta.X0 = from.XRightAfter;
                        ta.X1 = to.XLeftAfter;
                        ta.XText = from.XClearRight;
                    }
                    else
                    {
                        ta.X0 = from.XLeftAfter;
                        ta.X1 = to.XRightAfter;
                        ta.XText = from.XClearLeft;
                    }
                }
                else
                {
                    SelfTextArrow sta = new SelfTextArrow();
                    sta.Y0 = YCurrent - 10;
                    sta.Y1 = YCurrent;
                    sta.X0 = from.XRightBefore;
                    sta.X0b = from.XRightAfter;
                    sta.X1 = from.XRightBefore + 30;
                    sta.XText = from.XClearRight;
                    ta = sta;
                }

                ta.Text = arrow.text;
                ta.ArrowKind = arrow.type;
                ta.Layout(cr);
                items.Add(ta);
            }
        }

        foreach(LifeLine ll in lifeLines)
        {
            ll.End();
        }

        height = YCurrent;
    }