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



/*---------------------- Pro/Toolkit Includes ------------------------*/
#include <ProToolkit.h>
#include <ProSelection.h>
#include <ProFeature.h>
#include <ProArray.h>
#include <ProMdl.h>
#include <ProUtil.h>

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

/*---------------------- Function Prototypes -------------------------*/
ProError UserChildDisp();


/*============================================================================*\
	Function: UserChildDisp()
        Purpose: Display Children of selected feature
\*============================================================================*/
ProError UserChildDisp()
{
    int n, sel_count, kid_count;
    int *children=NULL;
    ProError status;
    ProFeature p_child;
    ProFileName msgfile;
    ProSelection *psels=NULL;
    ProMdl p_solid;
    ProModelitem p_mdl_item;
    ProAsmcomppath path;

/*----------------------------------------------------------------------------*\
	Prompt for selection of feature
\*----------------------------------------------------------------------------*/
    ProStringToWstring(msgfile,"msg_uggeom.txt");
    status = ProMessageDisplay(msgfile,"USER Select Feature:");
    if((ProSelect("feature",1,NULL,NULL,NULL,NULL,&psels, &sel_count) != 
       PRO_TK_NO_ERROR) || (sel_count < 1))
       return((int)PRO_TK_GENERAL_ERROR);

    ProMessageClear();
    status = ProSelectionModelitemGet(psels[0],&p_mdl_item);
    ERROR_CHECK( "UserChildDisp", "ProSelectionModelitemGet", status );
    
/*----------------------------------------------------------------------------*\
	Get selected feature's children
\*----------------------------------------------------------------------------*/
    status = ProFeatureChildrenGet(&p_mdl_item,&children, &kid_count);
    ERROR_CHECK( "UserChildDisp", "ProFeatureChildrenGet", status );
    status = ProSelectionAsmcomppathGet(psels[0],&path);
    ERROR_CHECK( "UserChildDisp", "ProSelectionAsmcomppathGet", status);
    status = ProMdlCurrentGet(&p_solid);
    ERROR_CHECK( "UserChildDisp","ProMdlCurrentGet",status);

/*----------------------------------------------------------------------------*\
	Highlight children
\*----------------------------------------------------------------------------*/
    for(n=0; n < kid_count; n++)
    {
       status = ProFeatureInit(p_solid,children[n],&p_child);
       ERROR_CHECK( "UserChildDisp","ProFeatureInit",status);
       if (status == PRO_TK_NO_ERROR)
	 {
	   status = ProSelectionSet(psels[0],&path,(ProModelitem *)&p_child);
	   ERROR_CHECK( "UserChildDisp", "ProSelectionSet", status);
	 }
       if (status == PRO_TK_NO_ERROR)
	 {
	   status = ProSelectionHighlight(psels[0], PRO_COLOR_ERROR);
	   ERROR_CHECK( "UserChildDisp", "ProSelectionHighlight", status );
	 }
    }

    ProArrayFree((ProArray *)&children);
    return(PRO_TK_NO_ERROR);
}