GetDashStyle
(
IEdge oEdge,
Double dWidth,
Boolean bDrawAsSelected
)
{
Debug.Assert(oEdge != null);
Debug.Assert(dWidth >= 0);
AssertValid();
// Note:
//
// An early implementation used the predefined DashStyle objects
// provided by the DashStyles class, but those did not look good at
// smaller edge widths. This implementation builds the DashStyle's
// Dashes collection from scratch.
Double [] adDashes = null;
if (!bDrawAsSelected)
{
Object oPerEdgeStyleAsObject;
// Check for a per-edge style.
if ( oEdge.TryGetValue(ReservedMetadataKeys.PerEdgeStyle,
typeof(EdgeStyle), out oPerEdgeStyleAsObject) )
{
switch ( (EdgeStyle)oPerEdgeStyleAsObject )
{
case EdgeStyle.Solid:
break;
case EdgeStyle.Dash:
adDashes = new Double[] {4.0, 2.0};
break;
case EdgeStyle.Dot:
adDashes = new Double[] {1.0, 2.0};
break;
case EdgeStyle.DashDot:
adDashes = new Double[] {4.0, 2.0, 1.0, 2.0};
break;
case EdgeStyle.DashDotDot:
adDashes = new Double[] {4.0, 2.0, 1.0, 2.0, 1.0, 2.0};
break;
default:
throw new FormatException( String.Format(
"{0}: The edge with the ID {1} has an invalid {2}"
+ " value."
,
this.ClassName,
oEdge.ID,
"ReservedMetadataKeys.PerEdgeStyle"
) );
}
}
}
if (adDashes == null)
{
return (DashStyles.Solid);
}
DashStyle oDashStyle = new DashStyle();
oDashStyle.Dashes = new DoubleCollection(adDashes);
WpfGraphicsUtil.FreezeIfFreezable(oDashStyle);
return (oDashStyle);
}