/*
	Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved.
*/

#include <ProToolkit.h>
#include <ProDtlsyminst.h>


/*====================================================================*\
FUNCTION : UsrSymInstCreate() 
PURPOSE  :  Create a symbol with no leaders at a specified location  
\*====================================================================*/ 
int UsrSymInstCreate(
     ProDrawing drawing,
     ProDtlsymdef *definition,
     ProVector pos
)
 {
     ProDtlsyminstdata sdata;
     ProDtlattach attach;
     ProDtlsyminst syminst;

/*--------------------------------------------------------------------*\ 
    Allocate the symbol instance decription 
\*--------------------------------------------------------------------*/     
    ProDtlsyminstdataAlloc(drawing, &sdata);

/*--------------------------------------------------------------------*\ 
    Set the definition this is an instance of 
\*--------------------------------------------------------------------*/     
    ProDtlsyminstdataDefSet(sdata, definition);

/*--------------------------------------------------------------------*\ 
    Set the attachment type to FREE 
\*--------------------------------------------------------------------*/     
    ProDtlsyminstdataAttachtypeSet(sdata, PROSYMDEFATTACHTYPE_FREE);

/*--------------------------------------------------------------------*\ 
    Allocate a FREE attachment and set the position 
\*--------------------------------------------------------------------*/     
    ProDtlattachAlloc(PRO_DTLATTACHTYPE_FREE, NULL, pos, NULL, &attach);
    ProDtlsyminstdataAttachmentSet(sdata, attach);
    ProDtlattachFree(attach);

/*--------------------------------------------------------------------*\ 
    Create the symbol and free the description 
\*--------------------------------------------------------------------*/     
    ProDtlsyminstCreate(drawing, sdata, &syminst);
    ProDtlsyminstdataFree(sdata);

/*--------------------------------------------------------------------*\ 
    Display the symbol 
\*--------------------------------------------------------------------*/
     ProDtlsyminstShow(&syminst);
 }

int UsrSymInstCreateWrapper ()
{
  ProError err;
  ProDrawing drawing;
  ProMdlType mdl_type;
  ProDtlsymdef *symdefs;
  int sheet, ns, s;
  ProVector pos;

  
  err = ProMdlCurrentGet ((ProMdl*)&drawing);
  if (err != PRO_TK_NO_ERROR)
    return (err);
  err = ProMdlTypeGet ((ProMdl)drawing, &mdl_type);
  if (mdl_type != PRO_MDL_DRAWING)
    return (PRO_TK_INVALID_TYPE);

  ProDrawingDtlsymdefsCollect(drawing, &symdefs);
  
  ProArraySizeGet(symdefs, &ns);
  
  for(s=0;s<ns;s++)
    {
      pos[0] = 100.0 +  s * 100.0;
      pos[1] = 400.0;
      pos[2] = 0.0;
      
      UsrSymInstCreate(drawing, &symdefs[s], pos);
    }

  return (PRO_TK_NO_ERROR);
}