/// <summary> /// Replacement for BinaryLinkShapeGeometry.DoPaintGeometry /// </summary> protected override void DoPaintGeometry(DiagramPaintEventArgs e, IGeometryHost geometryHost) { LinkShape linkShape; IJumpFreeLinkShape jumpFreeShape; VGObjectLineJumpCode expectedJumpCode; if (null != (jumpFreeShape = geometryHost as IJumpFreeLinkShape) && null != (linkShape = geometryHost as LinkShape) && linkShape.RouteJumpType != (expectedJumpCode = (jumpFreeShape.IsJumpFree ? VGObjectLineJumpCode.VGObjectJumpCodeNever : VGObjectLineJumpCode.VGObjectJumpCodePage))) { // Backup plan, sometimes we can't set this during configuration, and // it tends to revert in undo/redo scenarios when the backing graph // wrapper is not preserved. linkShape.RouteJumpType = expectedJumpCode; } Graphics g = e.Graphics; GraphicsPath path = this.GetPath(geometryHost); StyleSetResourceId penId = GetOutlinePenId(geometryHost); Pen pen = geometryHost.GeometryStyleSet.GetPen(penId); if ((path != null) && (pen != null)) { IDynamicColorGeometryHost dynamicColors = geometryHost as IDynamicColorGeometryHost; if (this.HasOutline(geometryHost)) { Color restoreColor; if (null == (dynamicColors = geometryHost as IDynamicColorGeometryHost) || (restoreColor = dynamicColors.UpdateDynamicColor(penId, pen)).IsEmpty) { restoreColor = geometryHost.UpdateGeometryLuminosity(e.View, pen); } else { geometryHost.UpdateGeometryLuminosity(e.View, pen); } GeometryUtility.SafeDrawPath(g, pen, path); pen.Color = restoreColor; } IBinaryLinkGeometryData hostData; EdgePointCollection edgePoints; int edgePointCount; if (null != (hostData = geometryHost as IBinaryLinkGeometryData) && null != (edgePoints = hostData.GeometryEdgePoints) && 1 < (edgePointCount = edgePoints.Count)) { float rotationAngle = 0f; LinkDecorator decorator; if (null != (decorator = hostData.GeometryDecoratorFrom)) { rotationAngle = CalculateRotationAngle(edgePoints[0].Point, edgePoints[1].Point); DrawDecorator(e, geometryHost, rotationAngle, edgePoints[0].Point, decorator #if VISUALSTUDIO_10_0 , hostData.GeometryDecoratorFromSize #endif ); } if (null != (decorator = hostData.GeometryDecoratorTo)) { rotationAngle = CalculateRotationAngle(edgePoints[edgePointCount - 1].Point, edgePoints[edgePointCount - 2].Point); DrawDecorator(e, geometryHost, rotationAngle, edgePoints[edgePointCount - 1].Point, decorator #if VISUALSTUDIO_10_0 , hostData.GeometryDecoratorToSize #endif ); } } } }
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; } }
/// <summary> /// Replacement for BinaryLinkShapeGeometry.DoPaintGeometry /// </summary> protected override void DoPaintGeometry(DiagramPaintEventArgs e, IGeometryHost geometryHost) { LinkShape linkShape = geometryHost as LinkShape; if (linkShape != null && linkShape.RouteJumpType != VGObjectLineJumpCode.VGObjectJumpCodeNever) { // Backup plan, sometimes we can't set this during configuration, and // it tends to revert in undo/redo scenarios when the backing graph // wrapper is not preserved. linkShape.RouteJumpType = VGObjectLineJumpCode.VGObjectJumpCodeNever; } Graphics g = e.Graphics; GraphicsPath path = this.GetPath(geometryHost); StyleSetResourceId penId = GetOutlinePenId(geometryHost); Pen pen = geometryHost.GeometryStyleSet.GetPen(penId); if ((path != null) && (pen != null)) { IDynamicColorGeometryHost dynamicColors = geometryHost as IDynamicColorGeometryHost; if (this.HasOutline(geometryHost)) { Color restoreColor; if (null == (dynamicColors = geometryHost as IDynamicColorGeometryHost) || (restoreColor = dynamicColors.UpdateDynamicColor(penId, pen)).IsEmpty) { restoreColor = geometryHost.UpdateGeometryLuminosity(e.View, pen); } else { geometryHost.UpdateGeometryLuminosity(e.View, pen); } GeometryUtility.SafeDrawPath(g, pen, path); pen.Color = restoreColor; } IBinaryLinkGeometryData hostData; EdgePointCollection edgePoints; int edgePointCount; if (null != (hostData = geometryHost as IBinaryLinkGeometryData) && null != (edgePoints = hostData.GeometryEdgePoints) && 1 < (edgePointCount = edgePoints.Count)) { float rotationAngle = 0f; LinkDecorator decorator; if (null != (decorator = hostData.GeometryDecoratorFrom)) { rotationAngle = CalculateRotationAngle(edgePoints[0].Point, edgePoints[1].Point); DrawDecorator(e, geometryHost, rotationAngle, edgePoints[0].Point, decorator #if VISUALSTUDIO_10_0 , hostData.GeometryDecoratorFromSize #endif ); } if (null != (decorator = hostData.GeometryDecoratorTo)) { rotationAngle = CalculateRotationAngle(edgePoints[edgePointCount - 1].Point, edgePoints[edgePointCount - 2].Point); DrawDecorator(e, geometryHost, rotationAngle, edgePoints[edgePointCount - 1].Point, decorator #if VISUALSTUDIO_10_0 , hostData.GeometryDecoratorToSize #endif ); } } } }
/// <summary> /// Paint the solid crowsfoot on the end of an optional line /// </summary> protected override void DoPaintGeometry(DiagramPaintEventArgs e, IGeometryHost geometryHost) { EntityRelationshipBinaryMultiplicityDisplay displaySetting = OptionsPage.CurrentEntityRelationshipBinaryMultiplicityDisplay; RolePlayerLink connector; EdgePointCollection edgePoints; int edgePointCount; Pen pen; ShapeElement shapeHost; IOffsetBorderPoint offsetPointProvider; if (displaySetting == EntityRelationshipBinaryMultiplicityDisplay.Barker && RoleMultiplicity.ZeroToMany == (connector = (RolePlayerLink)geometryHost).GetDisplayRoleMultiplicity(displaySetting) && null != (edgePoints = connector.EdgePoints) && 1 < (edgePointCount = edgePoints.Count) && null != (shapeHost = connector.ToShape) && null != (offsetPointProvider = shapeHost.ShapeGeometry as IOffsetBorderPoint) && null != (pen = geometryHost.GeometryStyleSet.GetPen(DiagramPens.ConnectionLine))) { Color restoreColor = pen.Color; pen.Color = geometryHost.UpdateGeometryLuminosity(e.View, pen); PointD pointOnBorder = edgePoints[edgePointCount - 1].Point; double angle = GeometryUtility.CalculateRadiansRotationAngle(edgePoints[0].Point, pointOnBorder); PointD vertexPoint = pointOnBorder; vertexPoint.Offset(CrowsFootHeight * Math.Cos(angle), CrowsFootHeight * Math.Sin(angle)); e.Graphics.DrawLine(pen, PointD.ToPointF(vertexPoint), PointD.ToPointF(pointOnBorder)); PointD? offsetBorderPoint = offsetPointProvider.OffsetBorderPoint(shapeHost, pointOnBorder, vertexPoint, CrowsFootHalfWidth, CrowsFootParallelMode); if (offsetBorderPoint.HasValue) { e.Graphics.DrawLine(pen, PointD.ToPointF(vertexPoint), PointD.ToPointF(offsetBorderPoint.Value)); } offsetBorderPoint = offsetPointProvider.OffsetBorderPoint(shapeHost, pointOnBorder, vertexPoint, -CrowsFootHalfWidth, CrowsFootParallelMode); if (offsetBorderPoint.HasValue) { e.Graphics.DrawLine(pen, PointD.ToPointF(vertexPoint), PointD.ToPointF(offsetBorderPoint.Value)); } pen.Color = restoreColor; } base.DoPaintGeometry(e, geometryHost); }
/// <summary> /// Paint the background and outline of a <see cref="IGeometryHost"/> using /// dynamic colors provided by the <see cref="IDynamicColorGeometryHost"/> interface. /// This is a helper method designed to be called by an override of the <see cref="NodeShapeGeometry.DoPaintGeometry"/> method. /// </summary> /// <param name="e">The <see cref="DiagramPaintEventArgs"/> passed to DoPaintGeometry</param> /// <param name="geometryHost">The <see cref="IGeometryHost"/> passed to DoPaintGeometry</param> /// <param name="dynamicColors">The <see cref="IDynamicColorGeometryHost"/> retrieved from the <paramref name="geometryHost"/></param> /// <param name="shapeGeometry">The <see cref="ShapeGeometry"/> this is a helper for.</param> /// <param name="hasFilledBackground">The result of the <see cref="ShapeGeometry.HasFilledBackground"/> method</param> /// <param name="hasOutline">The result of the <see cref="ShapeGeometry.HasOutline"/> method</param> /// <remarks> /// The DoPaintGeometry override should look similar to /// <code> /// protected override void DoPaintGeometry(DiagramPaintEventArgs e, IGeometryHost geometryHost) /// { /// IDynamicColorGeometryHost dynamicColors = geometryHost as IDynamicColorGeometryHost; /// if (dynamicColors != null) /// { /// GeometryUtility.PaintDynamicColorGeometry(e, geometryHost, dynamicColors, this, this.HasFilledBackground(geometryHost), this.HasOutline(geometryHost)); /// } /// else /// { /// base.DoPaintGeometry(e, geometryHost); /// } /// } /// </code> /// </remarks> public static void PaintDynamicColorGeometry(DiagramPaintEventArgs e, IGeometryHost geometryHost, IDynamicColorGeometryHost dynamicColors, ShapeGeometry shapeGeometry, bool hasFilledBackground, bool hasOutline) { if (hasFilledBackground || hasOutline) { StyleSet geometryStyleSet = geometryHost.GeometryStyleSet; GraphicsPath path; StyleSetResourceId penId = null; Pen pen = null; StyleSetResourceId brushId = null; Brush brush = null; if (null != (path = shapeGeometry.GetPath(geometryHost)) && (!hasFilledBackground || null != (brush = geometryStyleSet.GetBrush(brushId = shapeGeometry.GetBackgroundBrushId(geometryHost)))) && (!hasOutline || null != (pen = geometryStyleSet.GetPen(penId = shapeGeometry.GetOutlinePenId(geometryHost))))) { Graphics g = e.Graphics; DiagramClientView clientView = e.View; Color restoreColor; if (brush != null) { restoreColor = Color.Empty; if (dynamicColors == null || (restoreColor = dynamicColors.UpdateDynamicColor(brushId, brush)).IsEmpty) { if (clientView != null) { restoreColor = geometryHost.UpdateGeometryLuminosity(clientView, brush); } } else if (clientView != null) { geometryHost.UpdateGeometryLuminosity(clientView, brush); } g.FillPath(brush, path); SolidBrush solidBrush = brush as SolidBrush; if (!restoreColor.IsEmpty && null != (solidBrush = brush as SolidBrush)) { solidBrush.Color = restoreColor; } } if (pen != null) { restoreColor = Color.Empty; if (dynamicColors == null || (restoreColor = dynamicColors.UpdateDynamicColor(penId, pen)).IsEmpty) { if (clientView != null) { restoreColor = geometryHost.UpdateGeometryLuminosity(clientView, pen); } } else if (clientView != null) { geometryHost.UpdateGeometryLuminosity(clientView, pen); } SafeDrawPath(g, pen, path); if (!restoreColor.IsEmpty) { pen.Color = restoreColor; } } } } }
/// <summary> /// Reimplementation of <see cref="LinkDecorator.DoPaintShape"/> that /// recognizes <see cref="IDynamicColorGeometryHost"/> /// </summary> public override void DoPaintShape(RectangleD bounds, IGeometryHost shape, DiagramPaintEventArgs e) { StyleSet styleSet = shape.GeometryStyleSet; GraphicsPath decoratorPath = GetPath(bounds); StyleSetResourceId penId = PenId; Pen pen = styleSet.GetPen(penId); StyleSetResourceId brushId = BrushId; Brush brush = styleSet.GetBrush(brushId); if (((decoratorPath != null) && (pen != null)) && (brush != null)) { DiagramClientView clientView = e.View; IDynamicColorGeometryHost dynamicColors = shape as IDynamicColorGeometryHost; Graphics g = e.Graphics; Color restoreColor; if (FillDecorator) { restoreColor = Color.Empty; if (dynamicColors == null || (restoreColor = dynamicColors.UpdateDynamicColor(brushId, brush)).IsEmpty) { if (clientView != null) { restoreColor = shape.UpdateGeometryLuminosity(clientView, brush); } } else if (clientView != null) { shape.UpdateGeometryLuminosity(clientView, brush); } g.FillPath(brush, decoratorPath); SolidBrush solidBrush; if (!restoreColor.IsEmpty && null != (solidBrush = brush as SolidBrush)) { solidBrush.Color = restoreColor; } } restoreColor = Color.Empty; if (dynamicColors == null || (restoreColor = dynamicColors.UpdateDynamicColor(penId, pen)).IsEmpty) { if (clientView != null) { restoreColor = shape.UpdateGeometryLuminosity(clientView, pen); } } else if (clientView != null) { shape.UpdateGeometryLuminosity(clientView, pen); } GeometryUtility.SafeDrawPath(e.Graphics, pen, decoratorPath); if (!restoreColor.IsEmpty) { pen.Color = restoreColor; } } }