<?xml encoding=”UTF-8″>By Balaji Ramamoorthy
To interrupt and cancel the AcGsView::RenderToImage call while its doing the rendering, create a custom progress monitor class. In the class derived from AcGsRenderProgressMonitor, override the OnProgress method and return true to stop the RenderToImage. AutoCAD UI may not react to mouse events when the rendering is underway. To ensure that the AutoCAD UI is responsive during the rendering and to let the user cancel the operation, pump the Windows messages from OnProgress method.
Here is a sample code snippet :
<span>#include</span><span> <span>"acgsRender.h"</span><span> </span></span>
<span>class</span><span> MyRenderProgressMonitor :</span>
<span>public</span><span> AcGsRenderProgressMonitor</span>
<span>{</span>
<span>public</span><span> :</span>
MyRenderProgressMonitor(<span>void</span><span> )<span>{</span><span>}</span></span>
~MyRenderProgressMonitor(<span>void</span><span> )<span>{</span><span>}</span></span>
<span>static</span><span> Adesk::Boolean gAbortRender;</span>
<span>virtual</span><span> <span>bool</span><span> OnProgress(Phase ePhase, </span></span>
<span>float</span><span> fProgress)</span>
<span>{</span>
<span>// Pump windows message to let AutoCAD</span><span> </span>
<span>// respond to user interaction. </span><span> </span>
<span>// User may want to cancel the rendering</span><span> </span>
CWinApp *app = acedGetAcadWinApp();
CWnd *wnd = app->GetMainWnd ();
MSG msg;
<span>while</span><span> (::PeekMessage (&msg, wnd->m_hWnd, </span>
0, 0, PM_NOREMOVE))
<span>{</span>
<span>if</span><span> (!app->PumpMessage()) </span>
<span>{</span>
<span>break</span><span> ; </span>
<span>}</span>
<span>}</span>
LONG lIdle = 0;
<span>while</span><span> (app->OnIdle (lIdle++));</span>
<span>if</span><span> (gAbortRender)</span>
<span>return</span><span> <span>true</span><span> ;</span></span>
<span>return</span><span> <span>false</span><span> ;</span></span>
<span>}</span>
<span>virtual</span><span> <span>void</span><span> OnTile(<span>int</span><span> x, <span>int</span><span> y, <span>int</span><span> w, </span></span></span></span></span>
<span>int</span><span> h, <span>const</span><span> BYTE* pPixels)</span></span>
<span>{</span><span>}</span>
<span>virtual</span><span> <span>void</span><span> SetStatistics(</span></span>
<span>const</span><span> AcGsRenderStatistics* pStats)</span>
<span>{</span><span>}</span>
<span>virtual</span><span> <span>bool</span><span> ShouldReuseDatabase()</span></span>
<span>{</span><span>return</span><span> <span>false</span><span> ;<span>}</span></span></span>
<span>}</span>;
Adesk::Boolean
MyRenderProgressMonitor::gAbortRender
= Adesk::kFalse;
To use it, create an instance of the progress monitor class and use it with RenderToImage as in this code snippet :
<span>// pView is an AcGsView </span><span> </span>
<span>// screenRect is an AcGsDCRect</span><span> </span>
MyRenderProgressMonitor pm;
AcDbMentalRayRenderSettings mentalRayRenderer;
<span>bool</span><span> ok = pView->RenderToImage(</span>
&imgSource,
&mentalRayRenderer,
&pm,
screenRect);

Leave a Reply