Retains information about how one vertex was drawn as a .
Inheritance: SquareVertexDrawingHistory
Ejemplo n.º 1
0
    DrawSimpleShape
    (
        IVertex oVertex,
        VertexShape eShape,
        GraphDrawingContext oGraphDrawingContext,
        DrawingContext oDrawingContext,
        DrawingVisualPlus oDrawingVisual,
        VisibilityKeyValue eVisibility,
        Boolean bDrawAsSelected,
        String sAnnotation,
        VertexLabelDrawer oVertexLabelDrawer,
        CollapsedGroupDrawingManager oCollapsedGroupDrawingManager
    )
    {
        Debug.Assert(oVertex != null);
        Debug.Assert(oGraphDrawingContext != null);
        Debug.Assert(oDrawingContext != null);
        Debug.Assert(oDrawingVisual != null);
        Debug.Assert(oVertexLabelDrawer != null);
        Debug.Assert(oCollapsedGroupDrawingManager != null);
        AssertValid();

        Double dRadius = GetRadius(oVertex);
        Color oColor = GetColor(oVertex, eVisibility, bDrawAsSelected);
        Point oVertexLocation = GetVertexLocation(oVertex);

        oDrawingVisual.SetEffect( GetSimpleShapeEffect(
            oGraphDrawingContext, dRadius, oColor) );

        Rect oVertexBounds;

        if (eShape == VertexShape.Triangle ||
            eShape == VertexShape.SolidTriangle)
        {
            oVertexBounds =
                WpfGraphicsUtil.TriangleBoundsFromCenterAndHalfWidth(
                    oVertexLocation, dRadius);
        }
        else if (eShape == VertexShape.SolidTaperedDiamond)
        {
            // Note that the bounds of a tapered diamond can't be calculated
            // using simple equations.  Instead, create the tapered diamond and
            // let WPF compute the bounds.
            //
            // There is some inefficiency here, because the tapered diamond
            // gets created again before it is drawn, in its possibly-moved
            // location.

            oVertexBounds = WpfPathGeometryUtil.GetTaperedDiamond(
                oVertexLocation, dRadius).Bounds;
        }
        else if (eShape == VertexShape.SolidRoundedX)
        {
            // Note that the bounds of a rounded X can't be calculated
            // using simple equations.  Instead, create the rounded X and
            // let WPF compute the bounds.
            //
            // There is some inefficiency here, because the rounded X
            // gets created again before it is drawn, in its possibly-moved
            // location.

            oVertexBounds = WpfPathGeometryUtil.GetRoundedX(
                oVertexLocation, dRadius).Bounds;
        }
        else
        {
            oVertexBounds = WpfGraphicsUtil.SquareFromCenterAndHalfWidth(
                oVertexLocation, dRadius);
        }

        // Move the vertex if it falls outside the graph rectangle.

        MoveVertexIfNecessary(oVertex, oGraphDrawingContext,
            oCollapsedGroupDrawingManager, ref oVertexBounds);

        oVertexLocation = GetVertexLocation(oVertex);
        VertexDrawingHistory oVertexDrawingHistory = null;

        // Note that for the "hollow" shapes -- Circle, Square, Diamond, and
        // Triangle -- Brushes.Transparent is used instead of a null brush.
        // This allows the entire area of these shapes to be hit-tested.  Using
        // a null brush would cause hit-testing to fail if the shapes'
        // interiors were clicked.

        switch (eShape)
        {
            case VertexShape.Circle:
            case VertexShape.Disk:

                Boolean bIsDisk = (eShape == VertexShape.Disk);

                oDrawingContext.DrawEllipse(
                    bIsDisk ? GetBrush(oColor) : Brushes.Transparent,
                    bIsDisk ? null : GetPen(oColor, DefaultPenThickness),
                    oVertexLocation, dRadius, dRadius
                    );

                oVertexDrawingHistory = bIsDisk ?

                    new DiskVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius)
                    :
                    new CircleVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.Sphere:

                RadialGradientBrush oRadialGradientBrush =
                    new RadialGradientBrush();

                oRadialGradientBrush.GradientOrigin =
                    oRadialGradientBrush.Center = new Point(0.3, 0.3);

                GradientStopCollection oGradientStops =
                    oRadialGradientBrush.GradientStops;

                oGradientStops.Add( new GradientStop(
                    WpfGraphicsUtil.SetWpfColorAlpha(Colors.White, oColor.A),
                    0.0) );

                oGradientStops.Add( new GradientStop(oColor, 1.0) );

                WpfGraphicsUtil.FreezeIfFreezable(oRadialGradientBrush);

                oDrawingContext.DrawEllipse(oRadialGradientBrush, null,
                    oVertexLocation, dRadius, dRadius);

                oVertexDrawingHistory = new SphereVertexDrawingHistory(
                    oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.Square:

                WpfGraphicsUtil.DrawPixelAlignedRectangle(oDrawingContext,
                    Brushes.Transparent, GetPen(oColor, DefaultPenThickness),
                    oVertexBounds);

                oVertexDrawingHistory = new SquareVertexDrawingHistory(oVertex,
                    oDrawingVisual, bDrawAsSelected, oVertexBounds);

                break;

            case VertexShape.SolidSquare:

                oDrawingContext.DrawRectangle(GetBrush(oColor), null,
                    oVertexBounds);

                oVertexDrawingHistory = new SolidSquareVertexDrawingHistory(
                    oVertex, oDrawingVisual, bDrawAsSelected, oVertexBounds);

                break;

            case VertexShape.Diamond:
            case VertexShape.SolidDiamond:

                Boolean bIsSolidDiamond = (eShape == VertexShape.SolidDiamond);

                PathGeometry oDiamond =
                    WpfPathGeometryUtil.GetDiamond(oVertexLocation, dRadius);

                oDrawingContext.DrawGeometry(

                    bIsSolidDiamond ? GetBrush(oColor) : Brushes.Transparent,

                    bIsSolidDiamond ? null :
                        GetPen(oColor, DefaultPenThickness),

                    oDiamond
                    );

                oVertexDrawingHistory = bIsSolidDiamond ?

                    new SolidDiamondVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius)
                    :
                    new DiamondVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.Triangle:
            case VertexShape.SolidTriangle:

                Boolean bIsSolidTriangle =
                    (eShape == VertexShape.SolidTriangle);

                PathGeometry oTriangle =
                    WpfPathGeometryUtil.GetTriangle(oVertexLocation, dRadius);

                oDrawingContext.DrawGeometry(

                    bIsSolidTriangle ? GetBrush(oColor) : Brushes.Transparent,

                    bIsSolidTriangle ? null :
                        GetPen(oColor, DefaultPenThickness),

                    oTriangle
                    );

                oVertexDrawingHistory = bIsSolidTriangle ?

                    new SolidTriangleVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius)
                    :
                    new TriangleVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.SolidTaperedDiamond:

                Geometry oTaperedDiamond =
                    WpfPathGeometryUtil.GetTaperedDiamond(
                        oVertexLocation, dRadius);

                // Note that as of August 2012, the tapered diamond shape is
                // used only for collapsed connector motifs.  Collapsed motifs
                // have an outline, so draw an outline here.

                oDrawingContext.DrawGeometry(GetBrush(oColor),

                    GetPen( CollapsedGroupDrawingManager
                        .GetCollapsedMotifOutlineColor(oColor.A),
                        DefaultPenThickness),

                    oTaperedDiamond);

                oVertexDrawingHistory =
                    new SolidTaperedDiamondVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.SolidRoundedX:

                Geometry oRoundedX =
                    WpfPathGeometryUtil.GetRoundedX(
                        oVertexLocation, dRadius);

                // Note that as of August 2012, the rounded X shape is
                // used only for collapsed clique motifs.  Collapsed motifs
                // have an outline, so draw an outline here.

                oDrawingContext.DrawGeometry(GetBrush(oColor),

                    GetPen(CollapsedGroupDrawingManager
                        .GetCollapsedMotifOutlineColor(oColor.A),
                        DefaultPenThickness),

                    oRoundedX);

                oVertexDrawingHistory =
                    new SolidRoundedXVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            default:

                Debug.Assert(false);
                break;
        }

        if (sAnnotation != null)
        {
            oVertexLabelDrawer.DrawLabel(oDrawingContext,
                oGraphDrawingContext, oVertexDrawingHistory,

                CreateFormattedTextWithWrap(sAnnotation, oColor,
                    m_oFormattedTextManager.FontSize),

                oColor);
        }

        Debug.Assert(oVertexDrawingHistory != null);

        return (oVertexDrawingHistory);
    }