TryDrawEdge
(
IEdge edge,
GraphDrawingContext graphDrawingContext,
out EdgeDrawingHistory edgeDrawingHistory
)
{
Debug.Assert(edge != null);
Debug.Assert(graphDrawingContext != null);
AssertValid();
edgeDrawingHistory = null;
if (graphDrawingContext.GraphRectangleMinusMarginIsEmpty)
{
return (false);
}
// If the edge is hidden, do nothing.
VisibilityKeyValue eVisibility = GetVisibility(edge);
if (eVisibility == VisibilityKeyValue.Hidden)
{
return (false);
}
DrawingVisual oDrawingVisual = new DrawingVisual();
using ( DrawingContext oDrawingContext = oDrawingVisual.RenderOpen() )
{
Boolean bDrawAsSelected = GetDrawAsSelected(edge);
Color oColor = GetColor(edge, eVisibility, bDrawAsSelected);
Double dWidth = GetWidth(edge);
DashStyle oDashStyle = GetDashStyle(edge, dWidth, bDrawAsSelected);
Boolean bDrawArrow =
(m_bDrawArrowOnDirectedEdge && edge.IsDirected);
IVertex oVertex1 = edge.Vertex1;
IVertex oVertex2 = edge.Vertex2;
if (edge.IsSelfLoop)
{
if ( !TryDrawSelfLoop(oVertex1, oDrawingContext,
graphDrawingContext, oColor, dWidth, bDrawArrow) )
{
// The edge's vertex is hidden, so the edge should be
// hidden also.
return (false);
}
}
else
{
VertexDrawingHistory oVertex1DrawingHistory,
oVertex2DrawingHistory;
Point oEdgeEndpoint1, oEdgeEndpoint2;
if (
!TryGetVertexInformation(oVertex1, oVertex2,
out oVertex1DrawingHistory, out oVertex2DrawingHistory,
out oEdgeEndpoint1, out oEdgeEndpoint2)
||
oEdgeEndpoint1 == oEdgeEndpoint2
)
{
// One of the edge's vertices is hidden, so the edge should
// be hidden also, or the edge has zero length.
return (false);
}
Pen oPen = GetPen(oColor, dWidth, oDashStyle);
Object oLabelAsObject;
String sLabel = null;
if ( edge.TryGetValue(ReservedMetadataKeys.PerEdgeLabel,
typeof(String), out oLabelAsObject)
&& oLabelAsObject != null)
{
sLabel = (String)oLabelAsObject;
}
if (m_eCurveStyle ==
EdgeCurveStyle.CurveThroughIntermediatePoints)
{
DrawCurveThroughIntermediatePoints(
edge, graphDrawingContext, oDrawingContext,
oVertex1DrawingHistory, oVertex2DrawingHistory,
oEdgeEndpoint1, oEdgeEndpoint2, oPen);
}
else if (this.ShouldDrawBezierCurve)
{
DrawBezierCurve(
edge, graphDrawingContext, oDrawingContext,
oEdgeEndpoint1, oEdgeEndpoint2, bDrawAsSelected,
bDrawArrow, oPen, oColor, dWidth, eVisibility, sLabel);
}
else
{
DrawStraightEdge(
edge, graphDrawingContext, oDrawingContext,
oEdgeEndpoint1, oEdgeEndpoint2, bDrawAsSelected,
bDrawArrow, oPen, oColor, dWidth, eVisibility, sLabel);
}
}
// Retain information about the edge that was drawn.
edgeDrawingHistory = new EdgeDrawingHistory(
edge, oDrawingVisual, bDrawAsSelected, dWidth);
return (true);
}
}