LAnnotation::SetSnapToGrid

#include "ltwrappr.h"

virtual L_INT LAnnotation::SetSnapToGrid(uSnapToGridMode, pOptions)

L_UINT uSnapToGridMode;

constant that specifies the snap-to-grid state (on or off)

pANNSNAPTOGRIDOPTIONS pOptions;

pointer to a structure that specifies snap-to-grid options

Sets the state (on or off), the look, and the behavior of the annotation snap-to-grid.

Parameter Description
uSnapToGridMode The constant that specifies the snap-to-grid state. Possible values are:
  Value Meaning
  ANN_SNAPTOGRID_OFF [0] The snap-to-grid feature is disabled.
  ANN_SNAPTOGRID_ON [1] The snap-to-grid feature is enabled, and is visible in automation design mode.
pOptions Pointer to the ANNSNAPTOGRIDOPTIONS structure that LEADTOOLS uses to customize the look and behavior of the snap-to-grid.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function is used to enable or disable a snap-to-grid, and to customize its appearance and behavior.

The snap-to-grid feature is used in annotation automation design mode to allow the user to precisely draw, locate, and align annotation objects. When snap-to-grid is enabled by setting the uSnapToGridMode parameter to ANN_SNAPTOGRID_ON, a grid pattern consisting of dots and lines is overlayed on the image. When creating annotations in design mode, each point snaps to the nearest grid point. This behavior holds for creating any annotation object EXCEPT the freehand annotation. When creating a freehand annotation, the individual points do NOT snap to the nearest grid point because this would adversely affect the behavior of the freehand. The snap-to-grid feature affects the moving of all annotations object types in the design mode, in that the bounding box of the annotation object snaps to the nearest grid point.

To quickly enable to disable the snap-to-grid, pass the appropriate constant for uSnapToGridMode parameter, and pass NULL for the pOptions parameter.

To customize the look and behavior of the snap-to-grid, declare a variable of type ANNSNAPTOGRIDOPTIONS, and pass the address of this variable for pOptions. For a detailed explanation of the annotation snap-to-grid feature, see the documentation for ANNSNAPTOGRIDOPTIONS.

Required DLLs and Libraries

LTANN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64.

See Also

Functions:

LAnnotation::GetSnapToGrid

Topics:

Annotation Objects - Automated Features

Example

This sample gets the current state of the snap-to-grid and changes the snap-to-grid to grid size of 10 lines, every ten row of dots. Solid red lines enable the snap to grid.

L_TCHAR* GetLineStyleString(L_UINT uLineStyle) 
{ 
   TCHAR *pszLineStyle = TEXT(""); 
   switch(uLineStyle) 
   { 
      case ANNLINE_SOLID: 
      pszLineStyle = TEXT("ANNLINE_SOLID"); 
      break; 
      case ANNLINE_DASH: 
      pszLineStyle = TEXT("ANNLINE_DASH"); 
      break; 
      case ANNLINE_DOT: 
      pszLineStyle = TEXT("ANNLINE_DOT"); 
      break; 
      case ANNLINE_DASHDOT: 
      pszLineStyle = TEXT("ANNLINE_DASHDOT"); 
      break; 
      case ANNLINE_DASHDOTDOT: 
      pszLineStyle = TEXT("ANNLINE_DASHDOTDOT"); 
      break; 
      case ANNLINE_NULL: 
      pszLineStyle = TEXT("ANNLINE_NULL"); 
      break; 
   } 
   return pszLineStyle; 
} 
L_VOID DisplaySnapToGrid(LAnnAutomation * plAutomation, L_TCHAR *pszTitle) 
{ 
   L_TCHAR szMsg[200] = {0}; 
   ANNSNAPTOGRIDOPTIONS options = {0}; 
   L_UINT uSnapToGridMode = ANN_SNAPTOGRID_OFF; 
   options.uStructSize = sizeof(ANNSNAPTOGRIDOPTIONS); 
   options.uFlags = ANNSNAPTOGRID_ALL; 
   L_INT nRet = plAutomation->GetSnapToGrid(&uSnapToGridMode, &options, sizeof(ANNSNAPTOGRIDOPTIONS)); 
   if (nRet == SUCCESS) 
   { 
      wsprintf(szMsg, TEXT("uSnapToGridMode[%s]\ncrGridColor[0x%x]\nuGridLength[%d]\nuLineSpacing[%d]\nuLineStyle[%s]\nbEnableSnap[%s]\nbShowGrid[%s]\nbAutoChangeGridLength[%s]"), 
      uSnapToGridMode == ANN_SNAPTOGRID_OFF ? TEXT("ANN_SNAPTOGRID_OFF") : TEXT("ANN_SNAPTOGRID_ON"), 
      options.crGridColor, 
      options.uGridLength, 
      options.uLineSpacing, 
      GetLineStyleString(options.uLineStyle), 
      options.bEnableSnap ? TEXT("TRUE") : TEXT("FALSE"), 
      options.bShowGrid ? TEXT("TRUE") : TEXT("FALSE"), 
      options.bAutoChangeGridLength ? TEXT("TRUE") : TEXT("FALSE") 
      ); 
      MessageBox(NULL, szMsg, pszTitle, MB_OK); 
   } 
} 
L_INT SampleAnnSetSnapToGridExample(LAnnAutomation * plAutomation) 
{ 
   L_INT nRet = SUCCESS; 
   // Make sure that the snap-to-grid features is enabled 
   plAutomation->SetOptions(OPTIONS_NEW_ALL | OPTIONS_NEW_SNAPTOGRID); 
   // Display current snap-to-grid settings 
   DisplaySnapToGrid(plAutomation, TEXT("Original Settings")); 
   // Change snap-to-grid to grid size of 10, lines every ten row of dots, solid red lines, and enable it 
   ANNSNAPTOGRIDOPTIONS options = {0}; 
   options.uStructSize = sizeof(ANNSNAPTOGRIDOPTIONS); 
   options.uFlags = ANNSNAPTOGRID_ALL; 
   options.bAutoChangeGridLength = TRUE; 
   options.bEnableSnap = TRUE; 
   options.bShowGrid = TRUE; 
   options.crGridColor = RGB(255,0,0); 
   options.uGridLength = 10; 
   options.uLineSpacing = 10; 
   options.uLineStyle = ANNLINE_SOLID; 
   options.nReserved = 0; 
   nRet = plAutomation->SetSnapToGrid(ANN_SNAPTOGRID_ON, &options); 
   if (nRet == SUCCESS) 
   { 
      DisplaySnapToGrid(plAutomation, TEXT("New Settings")); 
   } 
   return nRet; 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C++ Class Library Help