Esempio n. 1
0
 public void Run(Diagram diagram, Graphics g, DiagramPainter dp, ReferenceStyle style)
 {
     FillFromDiagram(diagram);
     foreach (Table tbl in tables.Values)
     {
         tbl.SetReferencePositions();
     }
     foreach (Reference r in refs.Values)
     {
         r.Draw(g, dp, style);
     }
 }
Esempio n. 2
0
            public void Draw(Graphics g, DiagramPainter dp, ReferenceStyle style)
            {
                Pen pen = dp.GetPen(style.LineColor, style.LineWidth);

                if (style.LineWay == LineWayType.Rectangular)
                {
                    if (Vector2D.AngleBetween(StartVec, EndVec) < 0.1) // asi to bude rovnobezne
                    {
                        /*
                         * Start          beglev
                         *
                         * m1             m2
                         *
                         * endlev         End
                         */
                        Point2D beglev = new Line2D(Start, StartVec.NormalVector).ComPoint(new Line2D(End, EndVec)) ?? new Point2D();
                        Point2D endlev = new Line2D(End, EndVec.NormalVector).ComPoint(new Line2D(Start, StartVec)) ?? new Point2D();
                        Point2D m1     = Start + (endlev - Start) / 2;
                        Point2D m2     = beglev + (End - beglev) / 2;
                        g.DrawLine(pen, (Point)Start, (Point)m1);
                        g.DrawLine(pen, (Point)m1, (Point)m2);
                        g.DrawLine(pen, (Point)m2, (Point)End);
                        ReferencePainter.DrawArrow(dp, g, (Point)m2, (Point)End, style.Arrow);
                    }
                    else
                    {
                        /*
                         * Start
                         *
                         *
                         * m         End
                         */
                        Point2D m = new Line2D(Start, StartVec).ComPoint(new Line2D(End, EndVec)) ?? new Point2D();
                        g.DrawLine(pen, (Point)Start, (Point)m);
                        g.DrawLine(pen, (Point)m, (Point)End);
                        ReferencePainter.DrawArrow(dp, g, (Point)m, (Point)End, style.Arrow);
                    }
                }
                if (style.LineWay == LineWayType.Direct)
                {
                    g.DrawLine(pen, Start, End);
                    ReferencePainter.DrawArrow(dp, g, (Point)Start, (Point)End, style.Arrow);
                }
            }
Esempio n. 3
0
        private static void DrawPolygonalFk(Graphics g, DiagramPainter dp, DiagramTableItem fromTable, DiagramTableItem toTable, int srccolindex, int dstcolindex, ReferenceStyle style)
        {
            Pen pen   = dp.GetPen(style.LineColor, style.LineWidth);
            int extwi = style.PolygonalHorDistance;

            var possibilities = new List <_Tmp>();

            possibilities.Add(new _Tmp {
                xsrc = fromTable.Left, dirsrc = -1, xdst = toTable.Left, dirdst = -1
            });
            possibilities.Add(new _Tmp {
                xsrc = fromTable.Left, dirsrc = -1, xdst = toTable.Right, dirdst = 1
            });
            possibilities.Add(new _Tmp {
                xsrc = fromTable.Right, dirsrc = 1, xdst = toTable.Left, dirdst = -1
            });
            possibilities.Add(new _Tmp {
                xsrc = fromTable.Right, dirsrc = 1, xdst = toTable.Right, dirdst = 1
            });

            _Tmp minpos = possibilities.MinKey(p => Math.Abs(p.xsrc - p.xdst));

            Point src = new Point(minpos.xsrc, fromTable.Y + fromTable.GetColumnJoinY(srccolindex));
            Point dst = new Point(minpos.xdst, toTable.Y + toTable.GetColumnJoinY(dstcolindex));

            g.DrawLine(pen, src.X, src.Y, src.X + extwi * minpos.dirsrc, src.Y);
            g.DrawLine(pen, src.X + extwi * minpos.dirsrc, src.Y, dst.X + extwi * minpos.dirdst, dst.Y);
            g.DrawLine(pen, dst.X + extwi * minpos.dirdst, dst.Y, dst.X, dst.Y);

            DrawArrow(dp, g, dst.X + extwi * minpos.dirdst, dst.Y, dst.X, dst.Y, style.Arrow);
        }
Esempio n. 4
0
        public static void DrawReferences(Diagram diagram, Graphics g, DiagramPainter dp, ReferenceStyle style)
        {
            var oldmode = g.SmoothingMode;

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            if (style.LineWay == LineWayType.Rectangular || style.LineWay == LineWayType.Direct)
            {
                DrawPointReferences(diagram, g, dp, style);
            }
            else if (style.LineWay == LineWayType.Polygonal)
            {
                foreach (DiagramTableItem fromTable in diagram.Tables)
                {
                    foreach (ForeignKey fk in fromTable.Table.GetConstraints <ForeignKey>())
                    {
                        DiagramTableItem toTable = diagram.FindTable(fk.PrimaryKeyTable);
                        if (toTable != null)
                        {
                            int srccolindex = fromTable.Table.Columns.GetIndex(fk.Columns[0].ColumnName);
                            int dstcolindex = toTable.Table.Columns.GetIndex(fk.PrimaryKeyColumns[0].ColumnName);
                            if (srccolindex < 0 || dstcolindex < 0)
                            {
                                continue;                                     // broken foreign key
                            }
                            DrawPolygonalFk(g, dp, fromTable, toTable, srccolindex, dstcolindex, style);
                        }
                    }
                }
            }
            g.SmoothingMode = oldmode;
        }
Esempio n. 5
0
        private static void DrawPointReferences(Diagram diagram, Graphics g, DiagramPainter dp, ReferenceStyle style)
        {
            RectReferencePainter painter = new RectReferencePainter();

            painter.Run(diagram, g, dp, style);
        }