LayOutOrDrawGraph()
{
AssertValid();
#if TRACE_LAYOUT_AND_DRAW
Debug.WriteLine("NodeXLControl: LayOutOrDrawGraph(), m_eLayoutState = "
+ m_eLayoutState);
#endif
Rect oGraphRectangle = this.GraphRectangle;
#if TRACE_LAYOUT_AND_DRAW
Debug.WriteLine("NodeXLControl: LayOutOrDrawGraph(), size = " +
oGraphRectangle.Width + " , " + oGraphRectangle.Height);
#endif
System.Drawing.Rectangle oGraphRectangle2 =
WpfGraphicsUtil.RectToRectangle(oGraphRectangle);
switch (m_eLayoutState)
{
case LayoutState.Stable:
break;
case LayoutState.LayoutRequired:
Debug.Assert(!m_oLayout.IsBusy);
FireLayingOutGraph();
m_oLastLayoutContext = new LayoutContext(oGraphRectangle2);
m_eLayoutState = LayoutState.LayingOut;
if (m_oLayout is SortableLayoutBase)
{
// If the vertex layout order has been set, tell the layout
// object to sort the vertices before laying them out.
( (SortableLayoutBase)m_oLayout ).
UseMetadataVertexSorter(m_oGraph);
}
// Start an asynchronous layout. The m_oLayout object will
// fire a LayOutGraphCompleted event when it is done.
m_oLayout.LayOutGraphAsync(
m_oGraph, m_oLastLayoutContext);
break;
case LayoutState.LayingOut:
break;
case LayoutState.LayoutCompleted:
// The asynchronous layout has completed and now the graph
// needs to be drawn.
m_eLayoutState = LayoutState.Stable;
// Has the size of the control changed since the layout was
// started?
System.Drawing.Rectangle oLastGraphRectangle =
m_oLastLayoutContext.GraphRectangle;
if (
oLastGraphRectangle.Width != oGraphRectangle2.Width
||
oLastGraphRectangle.Height != oGraphRectangle2.Height
)
{
// Yes. Transform the layout to the new size.
#if TRACE_LAYOUT_AND_DRAW
Debug.WriteLine("NodeXLControl: Transforming layout.");
#endif
m_oLastLayoutContext = TransformLayout(oGraphRectangle);
}
DrawGraph(oGraphRectangle);
break;
case LayoutState.TransformRequired:
// The control has been resized and now the graph's layout
// needs to be transformed to the new size.
m_oLastLayoutContext = TransformLayout(oGraphRectangle);
m_eLayoutState = LayoutState.Stable;
DrawGraph(oGraphRectangle);
break;
default:
Debug.Assert(false);
break;
}
}