Example #1
0
        public static void LayoutLine(DocDefinition defA, DocDefinition defB, List <DocPoint> list)
        {
            if (list == null)
            {
                return;
            }

            while (list.Count > 3)
            {
                list[list.Count - 1].Delete();
                list.RemoveAt(list.Count - 1);
            }
            while (list.Count < 3)
            {
                list.Add(new DocPoint());
            }
            DocPoint ptA = list[0];
            DocPoint ptM = list[1];
            DocPoint ptB = list[2];

            DocRectangle rB = null;

            if (defB != null)
            {
                rB = defB.DiagramRectangle;
            }

            LayoutLine(defA.DiagramRectangle, rB, ptA, ptM, ptB);
        }
Example #2
0
        private static bool HitTest(DocRectangle docRect, Point pt, out ResizeHandle handle)
        {
            handle = ResizeHandle.None;

            if (docRect == null)
            {
                return(false);
            }

            Rectangle rc = new Rectangle(
                (int)(docRect.X * Factor),
                (int)(docRect.Y * Factor),
                (int)(docRect.Width * Factor),
                (int)(docRect.Height * Factor));

            bool contains = rc.Contains(pt);

            if (contains)
            {
                int W = pt.X - rc.Left;
                int N = pt.Y - rc.Top;
                int S = rc.Bottom - pt.Y;
                int E = rc.Right - pt.X;

                int rad = 5;
                if (E < rad)
                {
                    handle |= ResizeHandle.East;
                }
                else if (W < rad)
                {
                    handle |= ResizeHandle.West;
                }
                if (S < rad)
                {
                    handle |= ResizeHandle.South;
                }
                else if (N < rad)
                {
                    handle |= ResizeHandle.North;
                }

                if (handle == ResizeHandle.None)
                {
                    handle = ResizeHandle.Move;
                }
            }
            return(contains);
        }
Example #3
0
        private DocRectangle LoadRectangle(g group)
        {
            DocRectangle docRectangle = null;

            if (group.rect != null && group.rect.Count == 1)
            {
                rect r = group.rect[0];

                docRectangle        = new DocRectangle();
                docRectangle.X      = Double.Parse(r.x) / CtlExpressG.Factor;
                docRectangle.Y      = Double.Parse(r.y) / CtlExpressG.Factor;
                docRectangle.Width  = Double.Parse(r.width) / CtlExpressG.Factor;
                docRectangle.Height = Double.Parse(r.height) / CtlExpressG.Factor;
            }

            return(docRectangle);
        }
Example #4
0
        private static void ExpandExtents(DocRectangle docRect, ref double cx, ref double cy)
        {
            if (docRect == null)
            {
                return;
            }

            if (docRect.X + docRect.Width > cx)
            {
                cx = docRect.X + docRect.Width;
            }

            if (docRect.Y + docRect.Height > cy)
            {
                cy = docRect.Y + docRect.Height;
            }
        }
Example #5
0
        /// <summary>
        /// Updates layout of node end of tree, adjusting tree segment as necessary
        /// </summary>
        /// <param name="docLine"></param>
        /// <param name="docDef"></param>
        public static void LayoutNode(DocLine docTree, DocLine docLine)
        {
            DocDefinition docDef = docLine.Definition;

            if (docLine.DiagramLine.Count >= 2)
            {
                while (docLine.DiagramLine.Count < 3)
                {
                    docLine.DiagramLine.Insert(1, new DocPoint());
                }

                // shortcut: make up a rectangle for the line -- don't use constructor as that will allocate as object to be serialized within current project
                DocRectangle fakeRectangle = (DocRectangle)System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(DocRectangle));
                fakeRectangle.X      = docTree.DiagramLine[docTree.DiagramLine.Count - 1].X;
                fakeRectangle.Y      = docTree.DiagramLine[docTree.DiagramLine.Count - 1].Y;
                fakeRectangle.Width  = 0;
                fakeRectangle.Height = 0;

                LayoutLine(fakeRectangle, docDef.DiagramRectangle, docLine.DiagramLine[0], docLine.DiagramLine[1], docLine.DiagramLine[2]);
            }
        }
Example #6
0
        private void DrawObjectBorder(Graphics g, SEntity obj, Pen pen)
        {
            if (obj is DocDefinition && ((DocDefinition)obj).DiagramRectangle != null)
            {
                DocRectangle docRect = ((DocDefinition)obj).DiagramRectangle;

                Rectangle rc = new Rectangle(
                    (int)(docRect.X * Factor),
                    (int)(docRect.Y * Factor),
                    (int)(docRect.Width * Factor),
                    (int)(docRect.Height * Factor));
                rc.Inflate(-2, -2);

                g.DrawRectangle(pen, rc);
            }
            else if (obj is DocAttribute)
            {
                DocAttribute docAttr = (DocAttribute)obj;
                if (docAttr.DiagramLine != null)
                {
                    for (int i = 0; i < docAttr.DiagramLine.Count - 1; i++)
                    {
                        g.DrawLine(pen,
                                   new Point((int)(docAttr.DiagramLine[i].X * Factor), (int)(docAttr.DiagramLine[i].Y * Factor)),
                                   new Point((int)(docAttr.DiagramLine[i + 1].X * Factor), (int)(docAttr.DiagramLine[i + 1].Y * Factor)));
                    }
                }
            }
            else if (obj is DocLine)
            {
                // tree point
                DocLine   docLine  = (DocLine)obj;
                DocPoint  docPoint = docLine.DiagramLine[docLine.DiagramLine.Count - 1];
                Rectangle rc       = new Rectangle((int)(docPoint.X * Factor), (int)(docPoint.Y * Factor), 0, 0);
                rc.Inflate(6, 6);
                g.DrawEllipse(pen, rc);
            }
        }
Example #7
0
        private static void ImportVexLine(OBJECT_LINE_LAYOUT layout, TEXT_LAYOUT textlayout, List<DocPoint> diagramLine, DocRectangle diagramLabel)
        {
            if (layout == null)
                return;

            diagramLine.Add(new DocPoint(layout.pline.startpoint.wx, layout.pline.startpoint.wy));

            int direction = layout.pline.startdirection;
            double posx = layout.pline.startpoint.wx;
            double posy = layout.pline.startpoint.wy;

            for (int i = 0; i < layout.pline.rpoint.Count; i++)
            {
                if (diagramLabel != null && textlayout != null &&
                    layout.textplacement != null &&
                    layout.textplacement.npos == i)
                {
                    diagramLabel.X = textlayout.x + posx;
                    diagramLabel.Y = textlayout.y + posy;
                    diagramLabel.Width = textlayout.width;
                    diagramLabel.Height = textlayout.height;
                }

                double offset = layout.pline.rpoint[i];
                if (direction == 1)
                {
                    posy += offset;
                    direction = 0;
                }
                else if (direction == 0)
                {
                    posx += offset;
                    direction = 1;
                }
                diagramLine.Add(new DocPoint(posx, posy));
            }
        }
Example #8
0
        /// <summary>
        /// Lays out points for connectors using straight segments where possible, falling back on elbows if below
        /// </summary>
        /// <param name="rcA">The source rectangle</param>
        /// <param name="rcB">The target rectangle - optional; if null then only the first point is resized</param>
        /// <param name="ptA">The source point, which is positioned along the perimeter of the source rectangle.</param>
        /// <param name="ptM">The elbow point, which may be the same as the source point (if none), or different if an elbow is needed.</param>
        /// <param name="ptB">The target point, which is positioned at the midpoint of one of the four edges of the target rectangle.</param>
        private static void LayoutLine(DocRectangle rcA, DocRectangle rcB, DocPoint ptA, DocPoint ptM, DocPoint ptB)
        {
            if (rcA == null || rcB == null)
            {
                return;
            }

            if (rcB.X > rcA.X + rcA.Width)
            {
                // to right
                ptB.X = rcB.X;
                ptB.Y = rcB.Y + rcB.Height / 2;
                ptA.X = rcA.X + rcA.Width;
                ptA.Y = ptB.Y;
                ptM.X = ptA.X;
                ptM.Y = ptA.Y;
                if (ptA.Y > rcA.Y + rcA.Height)
                {
                    // below
                    ptA.Y = rcA.Y + rcA.Height;
                }
                else if (ptA.Y < rcA.Y)
                {
                    // above
                    ptA.Y = rcA.Y;
                }
            }
            else if (rcB.X + rcB.Width < rcA.X)
            {
                // to left
                ptB.X = rcB.X + rcB.Width;
                ptB.Y = rcB.Y + rcB.Height / 2;
                ptA.X = rcA.X;
                ptA.Y = ptB.Y;
                ptM.X = ptA.X;
                ptM.Y = ptA.Y;
                if (ptA.Y > rcA.Y + rcA.Height)
                {
                    // below
                    ptA.Y = rcA.Y + rcA.Height;
                }
                else if (ptA.Y < rcA.Y)
                {
                    // above
                    ptA.Y = rcA.Y;
                }
            }
            else if (rcB.Y > rcA.Y + rcA.Height)
            {
                // to down
                ptB.X = rcB.X + rcB.Width / 2;
                ptB.Y = rcB.Y;
                ptA.X = ptB.X;
                ptA.Y = rcA.Y + rcA.Height;
                ptM.X = ptA.X;
                ptM.Y = ptA.Y;
                if (ptA.X > rcA.X + rcA.Width)
                {
                    // right
                    ptA.X = rcA.X + rcA.Width;
                }
                else if (ptA.X < rcA.X)
                {
                    // left
                    ptA.X = rcA.X;
                }
            }
            else if (rcB.Y + rcB.Height < rcA.Y)
            {
                // to up
                ptB.X = rcB.X + rcB.Width / 2;
                ptB.Y = rcB.Y + rcB.Height;
                ptA.X = ptB.X;
                ptA.Y = rcA.Y;
                ptM.X = ptA.X;
                ptM.Y = ptA.Y;
                if (ptA.X > rcA.X + rcA.Width)
                {
                    // right
                    ptA.X = rcA.X + rcA.Width;
                }
                else if (ptA.X < rcA.X)
                {
                    // left
                    ptA.X = rcA.X;
                }
            }
        }
Example #9
0
        /// <summary>
        /// Lays out points for connectors using straight segments where possible, falling back on elbows if below
        /// </summary>
        /// <param name="rcA">The source rectangle</param>
        /// <param name="rcB">The target rectangle - optional; if null then only the first point is resized</param>
        /// <param name="ptA">The source point, which is positioned along the perimeter of the source rectangle.</param>
        /// <param name="ptM">The elbow point, which may be the same as the source point (if none), or different if an elbow is needed.</param>
        /// <param name="ptB">The target point, which is positioned at the midpoint of one of the four edges of the target rectangle.</param>
        private static void LayoutLine(DocRectangle rcA, DocRectangle rcB, DocPoint ptA, DocPoint ptM, DocPoint ptB)
        {
            if (rcA == null || rcB == null)
                return;

            if (rcB.X > rcA.X + rcA.Width)
            {
                // to right
                ptB.X = rcB.X;
                ptB.Y = rcB.Y + rcB.Height / 2;
                ptA.X = rcA.X + rcA.Width;
                ptA.Y = ptB.Y;
                ptM.X = ptA.X;
                ptM.Y = ptA.Y;
                if (ptA.Y > rcA.Y + rcA.Height)
                {
                    // below
                    ptA.Y = rcA.Y + rcA.Height;
                }
                else if (ptA.Y < rcA.Y)
                {
                    // above
                    ptA.Y = rcA.Y;
                }
            }
            else if (rcB.X + rcB.Width < rcA.X)
            {
                // to left
                ptB.X = rcB.X + rcB.Width;
                ptB.Y = rcB.Y + rcB.Height / 2;
                ptA.X = rcA.X;
                ptA.Y = ptB.Y;
                ptM.X = ptA.X;
                ptM.Y = ptA.Y;
                if (ptA.Y > rcA.Y + rcA.Height)
                {
                    // below
                    ptA.Y = rcA.Y + rcA.Height;
                }
                else if (ptA.Y < rcA.Y)
                {
                    // above
                    ptA.Y = rcA.Y;
                }
            }
            else if (rcB.Y > rcA.Y + rcA.Height)
            {
                // to down
                ptB.X = rcB.X + rcB.Width / 2;
                ptB.Y = rcB.Y;
                ptA.X = ptB.X;
                ptA.Y = rcA.Y + rcA.Height;
                ptM.X = ptA.X;
                ptM.Y = ptA.Y;
                if (ptA.X > rcA.X + rcA.Width)
                {
                    // right
                    ptA.X = rcA.X + rcA.Width;
                }
                else if (ptA.X < rcA.X)
                {
                    // left
                    ptA.X = rcA.X;
                }
            }
            else if (rcB.Y + rcB.Height < rcA.Y)
            {
                // to up
                ptB.X = rcB.X + rcB.Width / 2;
                ptB.Y = rcB.Y + rcB.Height;
                ptA.X = ptB.X;
                ptA.Y = rcA.Y;
                ptM.X = ptA.X;
                ptM.Y = ptA.Y;
                if (ptA.X > rcA.X + rcA.Width)
                {
                    // right
                    ptA.X = rcA.X + rcA.Width;
                }
                else if (ptA.X < rcA.X)
                {
                    // left
                    ptA.X = rcA.X;
                }
            }
        }
Example #10
0
        private static bool HitTest(DocRectangle docRect, Point pt, out ResizeHandle handle)
        {
            handle = ResizeHandle.None;

            if (docRect == null)
                return false;

            Rectangle rc = new Rectangle(
                (int)(docRect.X * Factor),
                (int)(docRect.Y * Factor),
                (int)(docRect.Width * Factor),
                (int)(docRect.Height * Factor));

            bool contains = rc.Contains(pt);
            if(contains)
            {
                int W = pt.X - rc.Left;
                int N = pt.Y - rc.Top;
                int S = rc.Bottom - pt.Y;
                int E = rc.Right - pt.X;

                int rad = 5;
                if(E < rad)
                {
                    handle |= ResizeHandle.East;
                }
                else if (W < rad)
                {
                    handle |= ResizeHandle.West;
                }
                if(S < rad)
                {
                    handle |= ResizeHandle.South;
                }
                else if (N < rad)
                {
                    handle |= ResizeHandle.North;
                }

                if (handle == ResizeHandle.None)
                    handle = ResizeHandle.Move;
            }
            return contains;
        }
Example #11
0
        private static void ExpandExtents(DocRectangle docRect, ref double cx, ref double cy)
        {
            if (docRect == null)
                return;

            if (docRect.X + docRect.Width > cx)
                cx = docRect.X + docRect.Width;

            if (docRect.Y + docRect.Height > cy)
                cy = docRect.Y + docRect.Height;
        }