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


/*--------------------------------------------------------------------*\
Pro/Toolkit includes
\*--------------------------------------------------------------------*/
#include <ProToolkit.h>
#include <ProSelection.h>
#include <ProObjects.h>
#include <ProSolid.h>
#include <ProGeomitem.h>
#include <ProModelitem.h>
#include <ProMdl.h>

/*--------------------------------------------------------------------*\
Application includes
\*--------------------------------------------------------------------*/
#include "ProUtil.h"
#include "TestError.h"
#include "UtilMath.h"
#include "math.h"

/*====================================================================*\
FUNCTION : UserMakeSelections()
PURPOSE  : Obtain the ProSurface and ProModelitem for target surface. Also
           obtain the selected xyz point.
\*====================================================================*/
int UserMakeSelections(ProSurface *p_surf, ProModelitem *p_mdl_item, 
    Pro3dPnt xyz) 
{
    int status ; 		/* return status */
    ProName msg_file ; 		/* message file */
    ProSelection *p_sel ;   	/* selection  */
    int n_sel ; 		/* number of selections */

    ProStringToWstring(msg_file, "msg_ugfund.txt") ; 
    ProMessageDisplay(msg_file, "USER %0s", "Select a surface.") ; 

    status = ProSelect("surface", 1, NULL, NULL, NULL, NULL, &p_sel, &n_sel) ; 
    TEST_CALL_REPORT("ProSelect()", "UserSelectSurface()", 
		status, status !=PRO_TK_NO_ERROR);
    if (status != PRO_TK_NO_ERROR) 
    {
	ProMessageDisplay(msg_file, "USER %0s F", 
	    "Error during surface selection.") ; 
        return(status) ; 
    }

/*--------------------------------------------------------------------*\
    Get Modelitem from ProSelection, then get ProSurface.
\*--------------------------------------------------------------------*/
    status = ProSelectionModelitemGet(*p_sel, p_mdl_item) ; 
    TEST_CALL_REPORT("ProSelectionModelitemGet()", "UserSelectSurface()", 
		status, status !=PRO_TK_NO_ERROR);
    status = ProGeomitemToSurface( (ProGeomitem *) p_mdl_item, p_surf) ; 
    TEST_CALL_REPORT("ProGeomitemToSurface()", "UserSelectSurface()", 
		status, status !=PRO_TK_NO_ERROR);

/*--------------------------------------------------------------------*\
    Get the selected xyz point.
\*--------------------------------------------------------------------*/
    status = ProSelectionPoint3dGet(*p_sel, xyz) ; 
    TEST_CALL_REPORT("ProSelection3dPointGet()", "UserSelectSurface()", 
		status, status !=PRO_TK_NO_ERROR);

    return(PRO_TK_NO_ERROR) ; 
}