public DGMulticastNode(MulticastDecisionGraphNode mcdgn,
     StateNode state)
     : base(mcdgn, state)
 {
     this.mMcDgn = mcdgn;
     this.mTargetAnchor = new AnchorPoint(this, 1, 0);
 }
Example #2
0
            public void Undo()
            {
                AnchorPoint ap = this.mNode.mSliceAnchors[this.mSliceIndex];

                RandomNode.Slice slice
                    = this.mNode.mRandomNode.Slices[this.mSliceIndex];
                if (this.bAdd)
                {
                    ap.Edges.RemoveAt(this.mTargetIndex);
                    slice.Targets.RemoveAt(this.mTargetIndex);
                }
                else
                {
                    ap.Edges.Insert(this.mTargetIndex, this.mEdge);
                    DGNode node = this.mEdge.DstNode;
                    if (node == this.mNode)
                    {
                        node = this.mEdge.SrcNode;
                    }
                    slice.Targets.Insert(this.mTargetIndex, node.DGN);
                }
            }
Example #3
0
 public EdgeAction(bool add, int i, DGEdge edge, AnchorPoint ap)
 {
     if (edge == null)
     {
         throw new ArgumentNullException("edge");
     }
     if (ap == null)
     {
         throw new ArgumentNullException("ap");
     }
     if (i < 0)
     {
         throw new ArgumentOutOfRangeException("i");
     }
     if (add)
     {
         if (i > ap.Edges.Count)
         {
             throw new ArgumentOutOfRangeException("i");
         }
     }
     else
     {
         if (i >= ap.Edges.Count)
         {
             throw new ArgumentOutOfRangeException("i");
         }
         else if (ap.Edges[i] != edge)
         {
             throw new ArgumentException("ap.Edges[i] != edge");
         }
     }
     this.bAdd   = add;
     this.mIndex = i;
     this.mEdge  = edge;
     this.mAP    = ap;
 }
Example #4
0
        public override void UpdateVisualization()
        {
            if (this.mScene.StateView == null)
            {
                return;
            }
            SizeF    size;
            float    h, w;
            Graphics g = this.mScene.StateView.CreateGraphics();

            this.mHeadMGH = 7;
            this.mBodyMGH = 7;
            if (this.mSoPn.Parameter == null)
            {
                this.mParamString = null;
                w = 40;
            }
            else
            {
                this.mParamString = this.mSoPn.Parameter.Name;
                size          = g.MeasureString(this.mParamString, sHeadFont);
                w             = Math.Max(40, size.Width + 10);
                this.mHeadMGH = Math.Max(this.mHeadMGH, size.Height);
            }
            this.mCaseCount = this.mSoPn.CaseCount;
            if (this.mCaseCount == 0)
            {
                h = 0;
            }
            else
            {
                int         i;
                AnchorPoint ap;
                string      caseString;
                SelectOnParameterNode.Case[] cases = this.mSoPn.Cases;
                if (this.mCaseAnchors.Length < this.mCaseCount)
                {
                    AnchorPoint[] cAnchors
                        = new AnchorPoint[this.mCaseCount];
                    Array.Copy(this.mCaseAnchors, 0, cAnchors, 0,
                               this.mCaseAnchors.Length);
                    this.mCaseAnchors = cAnchors;
                    this.mCaseStrings = new string[this.mCaseCount];
                }
                for (i = 0; i < this.mCaseCount; i++)
                {
                    caseString           = cases[i].Value;
                    this.mCaseStrings[i] = caseString;
                    if (!string.IsNullOrEmpty(caseString))
                    {
                        size          = g.MeasureString(caseString, sBodyFont);
                        w             = Math.Max(w, size.Width + 5);
                        this.mBodyMGH = Math.Max(this.mBodyMGH, size.Height);
                    }
                    if (this.mCaseAnchors[i] == null)
                    {
                        ap = new AnchorPoint(this, 1, 0);
                        this.mCaseAnchors[i] = ap;
                    }
                }
                h = this.mHeadMGH + 2.5f;
                for (i = 0; i < this.mCaseCount; i++)
                {
                    h += this.mBodyMGH / 2;
                    ap = this.mCaseAnchors[i];
                    ap.SetPosition(w, h);
                    h += this.mBodyMGH / 2;
                }
                h = 10 * this.mCaseCount + 2.5f;
            }

            this.mEntryAnchor.SetPosition(0, 10);

            if (this.mBorderPath == null)
            {
                this.mBorderPath = new GraphicsPath();
                this.mHeadPath   = new GraphicsPath();
                this.mBodyPath   = new GraphicsPath();
            }
            this.mBorderPath.Reset();
            AddRoundedRectangle(this.mBorderPath,
                                0, 0, w, h + this.mHeadMGH + 2.5f, 5);
            this.mHeadPath.Reset();
            AddRoundedRectangle(this.mHeadPath,
                                0, 0, w, this.mHeadMGH + 2.5f, 5, RectCorners.Top);
            this.mBodyPath.Reset();
            AddRoundedRectangle(this.mBodyPath,
                                0, this.mHeadMGH + 2.5f, w, h, 5, RectCorners.Bottom);

            float bbp = 2 * AnchorPoint.Radius;

            this.BoundingBox = new RectangleF(-bbp, -bbp,
                                              w + 2 * bbp, h + this.mHeadMGH + 5 + 2 * bbp);
        }
Example #5
0
        public override void UpdateVisualization()
        {
            if (this.mScene.StateView == null)
            {
                return;
            }
            SizeF    size;
            float    h, w = 10;
            Graphics g = this.mScene.StateView.CreateGraphics();

            this.mSliceCount = this.mRandomNode.Slices.Count;
            this.mMGH        = 7;
            if (this.mSliceCount == 0)
            {
                h = 15;
            }
            else
            {
                int                     i;
                AnchorPoint             ap;
                string                  sliceString;
                List <RandomNode.Slice> slices = this.mRandomNode.Slices;
                if (this.mSliceAnchors.Length < this.mSliceCount)
                {
                    AnchorPoint[] sAnchors
                        = new AnchorPoint[this.mSliceCount];
                    Array.Copy(this.mSliceAnchors, 0, sAnchors, 0,
                               this.mSliceAnchors.Length);
                    this.mSliceAnchors = sAnchors;
                    this.mSliceStrings = new string[this.mSliceCount];
                }
                for (i = 0; i < this.mSliceCount; i++)
                {
                    sliceString           = slices[i].Weight.ToString();
                    size                  = g.MeasureString(sliceString, sTextFont);
                    w                     = Math.Max(w, size.Width + 5);
                    this.mMGH             = Math.Max(this.mMGH, size.Height);
                    this.mSliceStrings[i] = sliceString;
                }
                if (this.mSliceCount == 1)
                {
                    h = this.mMGH + 5;
                    this.mSliceStrings[0]
                        = slices[0].Weight.ToString();
                    if (this.mSliceAnchors[0] == null)
                    {
                        ap = new AnchorPoint(this, 1, 0);
                        ap.SetPosition(w, h / 2);
                        this.mSliceAnchors[0] = ap;
                    }
                }
                else
                {
                    this.mSliceStrings[0]
                        = slices[0].Weight.ToString();
                    ap  = this.mSliceAnchors[0];
                    if (ap == null)
                    {
                        ap = new AnchorPoint(this, 0, -1);
                        this.mSliceAnchors[0] = ap;
                    }
                    else
                    {
                        ap.SetDirection(0, -1);
                    }
                    ap.SetPosition(w / 2, 0);

                    h = this.mMGH * this.mSliceCount + 5;
                    this.mSliceCount--;
                    this.mSliceStrings[this.mSliceCount]
                        = slices[this.mSliceCount].Weight.ToString();
                    ap  = this.mSliceAnchors[this.mSliceCount];
                    if (ap == null)
                    {
                        ap = new AnchorPoint(this, 0, 1);
                        this.mSliceAnchors[this.mSliceCount] = ap;
                    }
                    else
                    {
                        ap.SetDirection(0, 1);
                    }
                    ap.SetPosition(w / 2, h);

                    h = this.mMGH + 2.5f;
                    for (i = 1; i < this.mSliceCount; i++)
                    {
                        this.mSliceStrings[i]
                            = slices[i].Weight.ToString();
                        ap  = this.mSliceAnchors[i];
                        if (ap == null)
                        {
                            ap = new AnchorPoint(this, 1, 0);
                            this.mSliceAnchors[i] = ap;
                        }
                        else
                        {
                            ap.SetDirection(1, 0);
                        }
                        h += this.mMGH / 2;
                        ap.SetPosition(w, h);
                        h += this.mMGH / 2;
                    }
                    this.mSliceCount++;
                    h = this.mMGH * this.mSliceCount + 5;
                }
            }

            this.mEntryAnchor.SetPosition(0, h / 2);

            if (this.mBorderPath == null)
            {
                this.mBorderPath = new GraphicsPath();
            }
            this.mBorderPath.Reset();
            AddRoundedRectangle(this.mBorderPath, 0, 0, w, h, 5);

            float bbp = 2 * AnchorPoint.Radius;

            this.BoundingBox = new RectangleF(
                -bbp, -bbp, w + 2 * bbp, h + 2 * bbp);
        }
Example #6
0
        public override void UpdateVisualization()
        {
            if (this.mScene.StateView == null)
            {
                return;
            }
            SizeF    size;
            float    h, w = 40;
            Graphics g = this.mScene.StateView.CreateGraphics();

            this.mCaseCount = this.mSoDn.CaseCount;
            this.mMGH       = 7;
            if (this.mCaseCount == 0)
            {
                h = 15;
            }
            else
            {
                int         i;
                AnchorPoint ap;
                State       caseValue;
                string      caseString;
                SelectOnDestinationNode.Case[] cases = this.mSoDn.Cases;
                if (this.mCaseAnchors.Length < this.mCaseCount)
                {
                    AnchorPoint[] cAnchors
                        = new AnchorPoint[this.mCaseCount];
                    Array.Copy(this.mCaseAnchors, 0, cAnchors, 0,
                               this.mCaseAnchors.Length);
                    this.mCaseAnchors = cAnchors;
                    this.mCaseStrings = new string[this.mCaseCount];
                }
                for (i = 0; i < this.mCaseCount; i++)
                {
                    caseValue            = cases[i].Value;
                    caseString           = caseValue == null ? null : caseValue.Name;
                    this.mCaseStrings[i] = caseString;
                    if (!string.IsNullOrEmpty(caseString))
                    {
                        size      = g.MeasureString(caseString, sTextFont);
                        w         = Math.Max(w, size.Width + 5);
                        this.mMGH = Math.Max(this.mMGH, size.Height);
                    }
                    if (this.mCaseAnchors[i] == null)
                    {
                        ap = new AnchorPoint(this, 1, 0);
                        this.mCaseAnchors[i] = ap;
                    }
                }
                h = 2.5f;
                for (i = 0; i < this.mCaseCount; i++)
                {
                    h += this.mMGH / 2;
                    ap = this.mCaseAnchors[i];
                    ap.SetPosition(w, h);
                    h += this.mMGH / 2;
                }
                h = this.mMGH * this.mCaseCount + 5;
            }

            if (this.mBorderPath == null)
            {
                this.mBorderPath = new GraphicsPath();
            }
            this.mBorderPath.Reset();
            AddRoundedRectangle(this.mBorderPath, 0, 0, w, h, 5);

            float bbp = 2 * AnchorPoint.Radius;

            this.BoundingBox = new RectangleF(
                -bbp, -bbp, w + 2 * bbp, h + 2 * bbp);
        }
Example #7
0
        public static RectangleF AddEdgePath(
            AnchorPoint srcAP, AnchorPoint dstAP,
            GraphElement owner, GraphicsPath path)
        {
            SizeF srcPt = srcAP.ItemTranslate(owner);
            SizeF dstPt = dstAP.ItemTranslate(owner);

            float d1 = sCurveSize;

            float x1 = srcPt.Width;
            float y1 = srcPt.Height;
            float x2 = x1 + d1 * srcAP.DirectionX;
            float y2 = y1 + d1 * srcAP.DirectionY;

            float x4 = dstPt.Width;
            float y4 = dstPt.Height;
            float x3 = x4 + d1 * dstAP.DirectionX;
            float y3 = y4 + d1 * dstAP.DirectionY;

            if (x1 == x2 && x3 == x4 && x2 == x3 &&
                Math.Abs(y4 - y1) < 2 * sCurveSize)
            {
                // Src & Dst lines are both vertical and intersect
                y2 = y3 = (y4 - y1) / 2;
            }
            else if (x1 != x2 || x3 != x4)
            {
                if (x1 == x2 &&
                    ((x3 <= x1 && x1 <= x4) || (x4 <= x1 && x1 <= x3)))
                {
                    // Src line is vertical
                    // y = d1 * x + b1 => b1 = y4 - d1 * x4
                    d1 = (y4 - y3) / (x4 - x3);
                    float y = d1 * (x1 - x4) + y4;
                    if ((y2 <= y && y <= y1) || (y1 <= y && y <= y2))
                    {
                        // Dst line intersects Src line at y
                        y3 = y2 = y;
                        x3 = x2;
                    }
                }
                else if (x3 == x4 &&
                         ((x1 <= x4 && x4 <= x2) || (x2 <= x4 && x4 <= x1)))
                {
                    // Dst line is vertical
                    // y = d1 * x + b1 => b1 = y1 - d1 * x1
                    d1 = (y2 - y1) / (x2 - x1);
                    float y = d1 * (x4 - x1) + y1;
                    if ((y4 <= y && y <= y3) || (y3 <= y && y <= y4))
                    {
                        // Src line intersects Dst line at y
                        y2 = y3 = y;
                        x2 = x3;
                    }
                }
                else
                {
                    float d3;
                    // y = d1 * x + b1 => b1 = y1 - d1 * x1
                    d1 = (y2 - y1) / (x2 - x1);
                    // y = d3 * x + b3 => b3 = y3 - d3 * x3
                    d3 = (y4 - y3) / (x4 - x3);
                    if (d1 == d3 && d1 * (y4 - y1) == x1 - x4)
                    {
                        // Src & Dst lines are parallel and aligned
                        x2 = x3 = (x1 + x4) / 2;
                        y2 = y3 = (y1 + y4) / 2;
                    }
                    else
                    {
                        // d1 * x + b1 = d3 * x + b3
                        // x = (b1 - b3) / (d3 - d1)
                        float x = (d3 * x3 - d1 * x1 - y3 + y1)
                                  / (d3 - d1);
                        float y = d1 * (x - x1) + y1;
                        if (x2 < x1)
                        {
                            d1 = x1;
                            x1 = x2;
                            x2 = d1;
                        }
                        if (y2 < y1)
                        {
                            d1 = y1;
                            y1 = y2;
                            y2 = d1;
                        }
                        if (x1 <= x && x <= x2 && y1 <= y && y <= y2)
                        {
                            // Src & Dst lines intersect at (x, y)
                            x2 = x3 = x;
                            y2 = y3 = y;
                        }
                        else
                        {
                            d1 = sCurveSize;
                            x2 = x1 + d1 * srcAP.DirectionX;
                            y2 = y1 + d1 * srcAP.DirectionY;
                        }
                        x1 = srcPt.Width;
                        y1 = srcPt.Height;
                    }
                }
            }

            path.AddBezier(x1, y1, x2, y2, x3, y3, x4, y4);

            if (x2 < x1)
            {
                d1 = x1;
                x1 = x2;
                x2 = d1;
            }
            x1 = Math.Min(x1, x3);
            x1 = Math.Min(x1, x4);
            x2 = Math.Max(x2, x3);
            x2 = Math.Max(x2, x4);

            if (y2 < y1)
            {
                d1 = y1;
                y1 = y2;
                y2 = d1;
            }
            y1 = Math.Min(y1, y3);
            y1 = Math.Min(y1, y4);
            y2 = Math.Max(y2, y3);
            y2 = Math.Max(y2, y4);

            d1 = 4;

            return(new RectangleF(
                       x1 - d1 / 2, y1 - d1 / 2, x2 - x1 + d1, y2 - y1 + d1));
        }