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


/*-------------------------- Pro/Toolkit includes ---------------------------*/
#include <ProToolkit.h>
#include <ProMdl.h>
#include <ProCsys.h>

/*-------------------------- Application includes ---------------------------*/
#include <TestError.h>



/*================================================================*\
FUNCTION  : UserModelDelete
PURPOSE   : Deletes a model from the current drawing-type object.
\*================================================================*/
int UserModelDelete ()
{
    int                 status;
    ProCharLine 	astr;
    ProFamilyMdlName      wname;
    ProMdlType		type;
    ProMdl 		p_draw, p_model;    
    char		name[PRO_FAMILY_MDLNAME_SIZE];
    ProFileName WMSGFIL = {'m','s','g','_','u','g','d','w','g','.','t','x','t','\0'};
    ProError err;

    /*------------------------------------------------------------*\
      Get the current model
    \*------------------------------------------------------------*/
    err = ProMdlCurrentGet(&p_draw);
    ERROR_CHECK("UserModelDelete","ProMdlCurrentGet",err);
    if (err != PRO_TK_NO_ERROR) return(err);

    /*------------------------------------------------------------*\
      Get the name and type of the model to add.
    \*------------------------------------------------------------*/
    status = UserUtilNameTypeGet(WMSGFIL, wname, &type );
    ERROR_CHECK("UserModelDelete","UserUtilNameTypeGet",status);
    if (status != PRO_TK_NO_ERROR) return(status);

    /*------------------------------------------------------------*\
      Retrieve the specified object into memory.
    \*------------------------------------------------------------*/
    err = ProMdlnameRetrieve(wname, (ProMdlfileType)type, (&p_model));
    ERROR_CHECK("UserModelDelete","ProMdlnameRetrieve",err);
    if (err != PRO_TK_NO_ERROR) return(err);

    /*------------------------------------------------------------*\
      Delete the model from the current drawing-type object.
    \*------------------------------------------------------------*/
    err = ProDrawingSolidDelete ((ProDrawing)p_draw, 
					  (ProSolid)p_model);
    ERROR_CHECK("UserModelDelete","ProDrawingSolidDelete", err);

    /*------------------------------------------------------------*\
      Print a message in the message window
    \*------------------------------------------------------------*/
    if (PRO_TK_NO_ERROR == err)
      {
	ProWstringToString(name, wname);
	ProTKSprintf(astr, "Model %s has been deleted from drawing", name);
	err = ProMessageDisplay (WMSGFIL,"USER %0s", astr);
	ERROR_CHECK("UserModelDelete","ProMessageDisplay",err);
	return (PRO_TK_NO_ERROR);
      }
    else
      {
	ProTKSprintf(astr, "Error %d in UserModelDelete", err);
        err = ProMessageDisplay (WMSGFIL,"USER %0s", astr);
        ERROR_CHECK("UserModelDelete","ProMessageDisplay",err);
        return (PRO_TK_GENERAL_ERROR);
      }
}