コード例 #1
0
                public EntitySide(PointD p, RectangleD bounds, EntitySideType type)
                {
                    _type = type;
                    switch (_type)
                    {
                    case EntitySideType.OnBottom:
                        _range = Math.Abs(bounds.Top - p.Y);
                        break;

                    case EntitySideType.OnLeft:
                        _range = Math.Abs(bounds.Right - p.X);
                        break;

                    case EntitySideType.OnRight:
                        _range = Math.Abs(bounds.Left - p.X);
                        break;

                    case EntitySideType.OnTop:
                        _range = Math.Abs(bounds.Bottom - p.Y);
                        break;
                    }
                }
コード例 #2
0
            private static void DrawAssociationEnd(
                DiagramPaintEventArgs e, IGeometryHost geometryHost,
                NodeShape node, PointD pointOnBorder, PointD endPoint,
                bool many, bool optional, bool id, string predicateText, ref PointF?lineEnd, bool bothOptional)
            {
                Pen                pen;
                ShapeElement       shapeHost;
                IOffsetBorderPoint offsetPointProvider;
                Font               font;
                Brush              brush;
                Graphics           g = e.Graphics;

                if (null != (shapeHost = node) &&
                    null != (offsetPointProvider = shapeHost.ShapeGeometry as IOffsetBorderPoint) &&
                    null != (pen = geometryHost.GeometryStyleSet.GetPen(DiagramPens.ConnectionLine)) &&
                    null != (font = geometryHost.GeometryStyleSet.GetFont(DiagramFonts.ConnectionLine)) &&
                    null != (brush = geometryHost.GeometryStyleSet.GetBrush(DiagramBrushes.ConnectionLineText)))
                {
                    Color restoreColor = pen.Color;
                    pen.Color = geometryHost.UpdateGeometryLuminosity(e.View, pen);
                    double angle       = GeometryUtility.CalculateRadiansRotationAngle(endPoint, pointOnBorder);
                    PointD vertexPoint = pointOnBorder;
                    vertexPoint.Offset(CrowsFootHeight * Math.Cos(angle), CrowsFootHeight * Math.Sin(angle));

                    #region draw the main line

                    Pen mainLinePen = (Pen)pen.Clone();
                    if (optional)
                    {
                        mainLinePen.DashPattern = DashPattern;
                        mainLinePen.DashOffset  = DashPattern[0];
                    }
                    if (many & optional)
                    {
                        if (!bothOptional)
                        {
                            g.DrawLine(mainLinePen, PointD.ToPointF(endPoint), PointD.ToPointF(vertexPoint));
                        }
                        else
                        {
                            lineEnd = PointD.ToPointF(vertexPoint);
                        }
                        g.DrawLine(pen, PointD.ToPointF(vertexPoint), PointD.ToPointF(pointOnBorder));
                    }
                    else
                    {
                        if (!bothOptional)
                        {
                            g.DrawLine(mainLinePen, PointD.ToPointF(endPoint), PointD.ToPointF(pointOnBorder));
                        }
                        else
                        {
                            lineEnd = PointD.ToPointF(pointOnBorder);
                        }
                    }
                    #endregion
                    #region draw crow's foot if necessary
                    if (many)
                    {
                        PointD?offsetBorderPoint = offsetPointProvider.OffsetBorderPoint(shapeHost, pointOnBorder, vertexPoint, CrowsFootHalfWidth, CrowsFootParallelMode);
                        if (offsetBorderPoint.HasValue)
                        {
                            g.DrawLine(pen, PointD.ToPointF(vertexPoint), PointD.ToPointF(offsetBorderPoint.Value));
                        }
                        offsetBorderPoint = offsetPointProvider.OffsetBorderPoint(shapeHost, pointOnBorder, vertexPoint, -CrowsFootHalfWidth, CrowsFootParallelMode);
                        if (offsetBorderPoint.HasValue)
                        {
                            g.DrawLine(pen, PointD.ToPointF(vertexPoint), PointD.ToPointF(offsetBorderPoint.Value));
                        }
                    }
                    #endregion
                    #region draw tick mark if necessary
                    if (id)
                    {
                        PointD oneMarkLeft = vertexPoint;
                        double cosAngle    = Math.Cos(angle);
                        double sinAngle    = Math.Sin(angle);

                        oneMarkLeft.Offset(InfEngInnerOneMarkOffset * cosAngle, InfEngInnerOneMarkOffset * sinAngle);
                        PointD oneMarkRight = oneMarkLeft;
                        oneMarkLeft.Offset(-InfEngMarkerHalfWidth * sinAngle, InfEngMarkerHalfWidth * cosAngle);
                        oneMarkRight.Offset(InfEngMarkerHalfWidth * sinAngle, -InfEngMarkerHalfWidth * cosAngle);

                        g.DrawLine(pen, PointD.ToPointF(oneMarkLeft), PointD.ToPointF(oneMarkRight));
                    }
                    #endregion
                    #region draw text

                    //determine the line's properties
                    double         edgeX = pointOnBorder.X;
                    double         edgeY = pointOnBorder.Y;
                    EntitySideType whichSideShapeIsOn = EntitySide.FindWhichSide(pointOnBorder, shapeHost.GeometryBoundingBox);
                    double         w = 0;            //, y = 0;
                    angle = Math.Atan2(Math.Abs(endPoint.Y - edgeY), Math.Abs(endPoint.X - edgeX));
                    double inDegrees = angle * 180 / Math.PI;
                    if (inDegrees < 0)
                    {
                        inDegrees += 360;
                    }

                    SizeF textSize = g.MeasureString(predicateText, font);
                    w = textSize.Width;
                    //y = Math.Abs(w * Math.Tan(angle));

                    //determine what to offset
                    double textX      = edgeX;
                    double textY      = edgeY;
                    double h          = textSize.Height;
                    bool   lessThan45 = inDegrees < 45;

                    switch (whichSideShapeIsOn)
                    {
                    case EntitySideType.OnBottom:
                        textY -= TextPaddingY + h;
                        if (lessThan45)
                        {
                            textX += TextPaddingX;
                        }
                        else
                        {
                            textX -= TextPaddingX + w;
                        }
                        break;

                    case EntitySideType.OnTop:
                        textY += TextPaddingY;
                        if (lessThan45)
                        {
                            textX -= TextPaddingX + w;
                        }
                        else
                        {
                            textX += TextPaddingX;
                        }
                        break;

                    case EntitySideType.OnLeft:
                        textX += TextPaddingX;
                        if (lessThan45)
                        {
                            textY -= TextPaddingY + h;
                        }
                        else
                        {
                            textY += TextPaddingY;
                        }
                        break;

                    case EntitySideType.OnRight:
                        textX -= TextPaddingX + w;
                        if (lessThan45)
                        {
                            textY += TextPaddingY;
                        }
                        else
                        {
                            textY -= TextPaddingY + h;
                        }
                        break;
                    }

                    //perform the drawing
                    g.DrawString(predicateText, font, brush, new PointF((float)textX, (float)textY));

                    #endregion

                    pen.Color = restoreColor;
                }
            }