/*============================================================================*\
FILE    : UgGeomChildDisp.c
PURPOSE : Pro/TOOLKIT User Guide Example
 
HISTORY..
DATE      BUILD   AUTHOR    MODIFICATIONS
04-dec-97 H-02-02 ljo       $$1    Created
\*============================================================================*/


/*---------------------- 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=NULL;

/*----------------------------------------------------------------------------*\
	Prompt for selection of feature
\*----------------------------------------------------------------------------*/
    ProStringToWstring(msgfile,"msg_uggeom.txt");
    path = (ProAsmcomppath *) calloc(1,sizeof(ProAsmcomppath));
    if(path == NULL)
      return((int)PRO_TK_GENERAL_ERROR);
    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);
       status = ProSelectionSet(psels[0],path,(ProModelitem *)&p_child);
       ERROR_CHECK( "UserChildDisp", "ProSelectionSet", status);
       status = ProSelectionHighlight(psels[0], PRO_COLOR_ERROR);
       ERROR_CHECK( "UserChildDisp", "ProSelectionHighlight", status );
    }

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