LVectorBase::CopyObject

#include "ltwrappr.h"

virtual L_INT LVectorBase::CopyObject(pLayerDst, pObjectDst, pObjectSrc );

virtual L_INT LVectorBase::CopyObject(pObjectSrc);

 LVectorLayer * pLayerDst;

/* pointer to a vector layer object */

 LVectorObject * pObjectDst;

/* pointer to a vector object */

 LVectorObject * pObjectSrc;

/* pointer to a vector object */

Copies a vector object to another vector object. This function is available in the LEADTOOLS Vector Imaging Pro Toolkit.

Parameter

Description

pLayerDst

Pointer to the destination vector layer. Pass NULL to copy the source vector object to the active layer of the destination vector object.

pObjectDst

Pointer to the destination vector object. If this parameter contains a valid address of an LVectorObject object, then pObjectDst will be updated with the newly copied vector object. If this parameter is NULL, the source vector object will still be copied to the destination vector.

pObjectSrc

Pointer to the source vector object. This parameter cannot be NULL. The LVectorObject can be obtained by calling LVectorBase::HitTest, LVectorBase::EnumObjects, LVectorBase::AddObject, or by calling LVectorBase::CopyObject again.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function can be used to do the following:

This function creates a new object that is a carbon copy of the source object, but they are not related. The source object can be deleted after the copying process without affecting the newly copied object.

Setting the pLayerDst parameter to NULL will copy the object into the current active layer in the LVectorBase object.

If the pObjectDst parameter is set to NULL, information about the newly added object will not be provided when the function returns.

Required DLLs and Libraries

LVKRN

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

See Also

Functions:

LVectorBase::AddObject, LVectorObject::ExplodeObject

Topics:

Working with Vector Objects

Example

This example is for LVectorBase::CopyObject(pLayerDst, pObjectDst, pObjectSrc).

This example copies all objects from active layer of vector source to vector dest (active layer)

Information is displayed about each copied object.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
//Example93
class LMyVectorLayer4: public LVectorLayer
{
public:
   LVectorBase *m_pVectorDst;
public:
   LMyVectorLayer4() {};
   virtual ~LMyVectorLayer4(){};
   virtual L_INT EnumObjectsCallBack(pVECTORHANDLE pVector, pVECTOROBJECT pObject);
};
L_INT LMyVectorLayer4::EnumObjectsCallBack(pVECTORHANDLE pVector, pVECTOROBJECT pObject)
{
   L_TCHAR *pszType = NULL;
   LVectorBase   VectorBase(pVector);
   LVectorObject VectorObject(pObject, &VectorBase);
   LVectorObject ResultObject;
   
   m_pVectorDst->CopyObject(NULL, &ResultObject, &VectorObject);
   L_INT nType = ResultObject.GetType();
   switch (nType)
   {
   case VECTOR_VERTEX:
      pszType = TEXT("VECTOR_VERTEX");
      break;
      
   case VECTOR_LINE:       
      pszType = TEXT("VECTOR_LINE       ");
      break;
      
   case VECTOR_RECTANGLE  :
      pszType = TEXT("VECTOR_RECTANGLE  ");
      break;
      
   case VECTOR_POLYLINE   :
      pszType = TEXT("VECTOR_POLYLINE   ");
      break;
      
   case VECTOR_POLYBEZIER :
      pszType = TEXT("VECTOR_POLYBEZIER ");
      break;
      
   case VECTOR_POLYGON    :
      pszType = TEXT("VECTOR_POLYGON    ");
      break;
      
   case VECTOR_ELLIPSE    :
      pszType = TEXT("VECTOR_ELLIPSE    ");
      break;
      
   case VECTOR_CIRCLE     :
      pszType = TEXT("VECTOR_CIRCLE     ");
      break;
      
   case VECTOR_ARC        :
      pszType = TEXT("VECTOR_ARC        ");
      break;
      
   case VECTOR_TEXT       :
      pszType = TEXT("VECTOR_TEXT       ");
      break;
      
   case VECTOR_PIE        :
      pszType = TEXT("VECTOR_PIE        ");
      break;
      
   case VECTOR_CHORD      :
      pszType = TEXT("VECTOR_CHORD      ");
      break;
      
   case VECTOR_POLYDRAW   :
      pszType = TEXT("VECTOR_POLYDRAW   ");
      break;
      
   case VECTOR_RASTER     :
      pszType = TEXT("VECTOR_RASTER     ");
      break;
      
   case VECTOR_STOCK     :
      pszType = TEXT("VECTOR_STOCK     ");
      break;
   }
   MessageBox(NULL, pszType, TEXT(""), MB_OK);
   VectorBase.SetHandle(NULL, FALSE);
   return SUCCESS ;
}
L_INT LVectorBase__CopyObjectExample_1(HWND hWnd, LVectorBase *pVectorDst)
{
   UNREFERENCED_PARAMETER(hWnd);
   L_INT       nRet;
   //Load a source vector
   LVectorBase VectorSrc;
   nRet = VectorSrc.Load (MAKE_IMAGE_PATH(TEXT("random.dxf")));
   if(nRet != SUCCESS)
      return nRet;
   //Get the active layer of source
   LMyVectorLayer4  VectorLayer;
   nRet = VectorSrc.GetActiveLayer(&VectorLayer);
   if(nRet != SUCCESS)
      return nRet;
   //Set the destination vector where objects from source will be copied
   VectorLayer.m_pVectorDst = pVectorDst;
   //Enumerate all objects in Active layer (and copy to dest vector)
   nRet = VectorLayer.EnumObjects();
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}
// This example is for LVectorBase::CopyObject(pObjectSrc).
// This example copies all objects from the active layer of the vector 
//source to the destination vector (active layer)
class LMyVectorLayerCO: public LVectorLayer
{
public:
   LVectorBase *m_pVectorDst;
public:
   LMyVectorLayerCO() {};
   virtual ~LMyVectorLayerCO(){};
   virtual L_INT EnumObjectsCallBack(pVECTORHANDLE pVector, pVECTOROBJECT pObject);
};
L_INT LMyVectorLayerCO::EnumObjectsCallBack(pVECTORHANDLE pVector, pVECTOROBJECT pObject)
{
   LVectorBase   VectorBase(pVector);
   LVectorObject VectorObject(pObject, &VectorBase);
   m_pVectorDst->CopyObject(&VectorObject);
   VectorBase.SetHandle(NULL, FALSE);
   return SUCCESS ;
}
L_INT LVectorBase__CopyObjectExample_2(HWND hWnd, LVectorBase *pVectorDst)
{
   UNREFERENCED_PARAMETER(hWnd);
   L_INT          nRet;
   //Load a source vector
   LVectorBase    VectorSrc;
   nRet = VectorSrc.Load(MAKE_IMAGE_PATH(TEXT("random.dxf")));
   if(nRet != SUCCESS)
      return nRet;
   //Get the active layer of source
   LMyVectorLayerCO VectorLayer;
   nRet = VectorSrc.GetActiveLayer(&VectorLayer);
   if(nRet != SUCCESS)
      return nRet;
   //Set the destination vector where objects from source will be copied
   VectorLayer.m_pVectorDst = pVectorDst;
   //Enumerate all objects in Active layer (and copy to dest vector)
   nRet = VectorLayer.EnumObjects();
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}