Implementing Automation - Implementing Vector Automation.

Start with the project you created in Initializing and loading a vector image

Take the following steps to create and initialize the automation objects:

1.

Add the following after #include "…\l_bitmap.h". Note that you need to change the path to match what is on your system.

#include "c:/Program Files/LEAD Technologies/LEADTOOLS 16/Include/ltpnt.h"
#include "c:/Program Files/LEAD Technologies/LEADTOOLS 16/Include/lttlb.h"
#include "c:/Program Files/LEAD Technologies/LEADTOOLS 16/Include/ltcon.h"
#include "c:/Program Files/LEAD Technologies/LEADTOOLS 16/Include/ltaut.h"

2.

Change the ResetView function to the following:

static L_VOID ResetView( HWND hWnd, pVECTORHANDLE pVector, pAUTOMATIONHANDLE pAutomation )
{
   VECTORPOINT Scale;
   VECTORPOINT Rotation;
   VECTORPOINT Translation;
   POINT       pt;

   L_AutSetUndoEnabled ( pAutomation, FALSE );

   Scale.x = Scale.y = Scale.z = 1.0;
   L_VecSetScale  ( pVector, &Scale, NULL, NULL, 0L );

   Rotation.x = Rotation.y = Rotation.z = 0.0;
   L_VecSetRotation  ( pVector, &Rotation, NULL, NULL, 0L );

   Translation.x = Translation.y = Translation.z = 0.0;
   L_VecSetTranslation  ( pVector, &Translation, NULL, 0L );

   pt.x = 0;
   pt.y = 0;

   L_VecSetPan  ( pVector, &pt );
   L_VecSetParallelogram  ( pVector, NULL, NULL );
   L_VecSetOrigin  ( pVector, NULL );
   L_VecSetCamera  ( pVector, NULL );

   L_AutSetUndoEnabled ( pAutomation, TRUE );

   InvalidateRect( hWnd, NULL, FALSE );
}

3.

Add this new local function before the WndProc function:

static L_INT EXT_CALLBACK ContainerCallback( pCONTAINERHANDLE pContainer, CONTAINEREVENTTYPE nEventType, L_VOID *pEventData, L_VOID *pUserData )
{
   HWND                 hWnd;
   pCONTAINEROBJECTDATA pObjectData;

   switch( nEventType )
   {
      case CONTAINER_EVENT_TYPE_DRAW:
         pObjectData = (pCONTAINEROBJECTDATA) pEventData;
         if( pObjectData->fState == CONTAINER_STATE_END || pObjectData->fState == CONTAINER_STATE_ABORT )
         {
            L_ContainerGetOwner ( pContainer, &hWnd );
            InvalidateRect( hWnd, NULL, FALSE );
         }
         break;
   }

   return SUCCESS;
}

4.

Add the following local variables to the WndProc function, right after the HDC hDC; statement:

static pAUTOMATIONHANDLE pAutomation;
static pCONTAINERHANDLE pContainer;
static pTOOLBARHANDLE pToolbar;
CONTAINERMETRICS ContainerMetrics;

5.

Add the following lines right after the L_VecAttachToWindow function call in WM_CREATE of WndProc:

         // create the automation handle
         L_AutInit( &pAutomation );
         L_AutCreate ( pAutomation, AUTOMATION_MODE_VECTOR, 0L );

         // create the toolbar
         L_TBInit  ( &pToolbar );
         L_TBCreate  ( pToolbar, hWnd, TEXT("Vector"), TOOLBAR_VECTOR );
         L_TBSetVisible  ( pToolbar, TRUE );

         // add it to the automation object
         L_AutSetToolbar ( pAutomation, pToolbar );

         // create the container
         L_ContainerInit ( &pContainer );
         L_ContainerCreate ( pContainer, hWnd );

         // set its callback
         L_ContainerSetCallback ( pContainer, ContainerCallback, NULL );

         // add it to the automation object
         L_AutAddContainer ( pAutomation, pContainer, &Vector );

         // set it as the active container
         L_AutSetActiveContainer ( pAutomation, pContainer );

6.

Change the ResetView function call just before the return 0; statement in WM_CREATE to:

ResetView( hWnd, &Vector, pAutomation ); 

7.

Add the following lines right after the L_VecSetViewport function call in WM_SIZE:

// set container limits to all client area
ContainerMetrics.nSize = sizeof( CONTAINERMETRICS );
ContainerMetrics.dwMask = CMF_LIMITS;
CopyRect( &ContainerMetrics.rcLimits, &Rect );
L_ContainerSetMetrics
 ( pContainer, &ContainerMetrics );

8.

Add these lines to the WM_DESTROY message, before the call to L_VecFree :

         // destroy container
         L_AutRemoveContainer ( pAutomation, pContainer );
         L_ContainerFree ( pContainer );

         // destroy automation
         L_AutFree ( pAutomation );

         // destroy toolbar
         L_TBFree  ( pToolbar ); 

9.

In Imports.cpp add the following #pragma comment lines. Note that you need to change the path to match what is on your system:

 

#if defined(FOR_WIN64) 



   #pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\x64\\Lvaut_x.lib")
   #pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\x64\\Lvcon_x.lib")
   #pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\x64\\Lvtlb_x.lib")



#elif defined(FOR_WIN32) 



   #pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\Win32\\Ltaut_u.lib")
   #pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\Win32\\Ltcon_u.lib")
   #pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\Win32\\Lttlb_u.lib")



#endif // #if defined(FOR_WIN64) 

10.

Compile and run the demo. You should be able to draw new vector objects and rotate in 3D, using your mouse and the pan feature.