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




/*--------------------------------------------------------------------*\
    Pro/TOOLKIT includes
\*--------------------------------------------------------------------*/
#include "ProToolkit.h"
#include "ProMdl.h"
#include "ProDisplist.h"
#include "ProMessage.h"
#include "ProMenu.h"
#include "ProUtil.h"


/*--------------------------------------------------------------------*\
    Pro/DEVELOP includes
\*--------------------------------------------------------------------*/


/*--------------------------------------------------------------------*\
    C System includes
\*--------------------------------------------------------------------*/


/*--------------------------------------------------------------------*\
    Application includes
\*--------------------------------------------------------------------*/
#include "TestError.h"
#include "TestGraphics.h"
#include "UtilMatrix.h"
#include "UtilMessage.h"


/*--------------------------------------------------------------------*\
    Macros
\*--------------------------------------------------------------------*/


/*--------------------------------------------------------------------*\
    Data types
\*--------------------------------------------------------------------*/
typedef enum tag_DispListActions
	{
	    DISP_LIST_DEL = 0,
	    DISP_LIST_CREATE,
	    DISP_LIST_DISPLAY
	} DispListActions;


/*--------------------------------------------------------------------*\
    Application global/external data
\*--------------------------------------------------------------------*/


/*---------------------------------------------------------------------*\
    Functions declaration
\*---------------------------------------------------------------------*/
int	    ProTest2dDisplistMenu( void*, int );
int	    ProTest2dDisplist( void*, int );
int	    ProTest3dDisplistMenu( void*, int );
int	    ProTest3dDisplist( void*, int );
int	    ProTestDisplistInvalidate( ProMdl*, int );
int         ProTestDisplistDraw( void );
int ProTestEntityDrawMenu( void* p_dummy, int int_dummy );


/*---------------------------------------------------------------------*\
    Function:	ProTest2dDisplistMenu()
    Purpose:	On-button function. Set up the display list menu
    Returns:	0 - success; -1 - error. Now ignored.
\*---------------------------------------------------------------------*/
int ProTest2dDisplistMenu( void* p_dummy, int int_dummy )
{
    ProError		status;
    int			menu_id;    /* The identifier of the created menu */
    int			action;
    ProMdl		part;

    
    /* Get current Pro/E object */
    status = ProMdlCurrentGet( &part );
    TEST_CALL_REPORT( "ProMdlCurrentGet()", "ProTest2dDisplistMenu()",
			status, status != PRO_TK_NO_ERROR);

    if( status == PRO_TK_BAD_CONTEXT )
    {
        ProUtilMsgPrint( "gen", "TEST %0s", "An object is required" );
        return (PRO_TK_GENERAL_ERROR);
    }


    /*---------------------------------*\
	Create new menu Disp List
    \*---------------------------------*/

    /* Load base menu from file */
    status = ProMenuFileRegister( (char*)"Disp List", (char*)"tkdlist.mnu", &menu_id );
    TEST_CALL_REPORT( "ProMenuFileRegister()", "ProTest2dDisplistMenu()", 
			status, status != PRO_TK_NO_ERROR );

    /* Define menu buttons */
    ProMenubuttonActionSet( (char*)"Disp List", (char*)"Cre DispList", 
	(ProMenubuttonAction)ProTest2dDisplist, NULL, DISP_LIST_CREATE );
    ProMenubuttonActionSet( (char*)"Disp List",(char*) "Del DispList", 
	(ProMenubuttonAction)ProTest2dDisplist, NULL, DISP_LIST_DEL );
    ProMenubuttonActionSet( (char*)"Disp List",(char*) "Disp DispList", 
	(ProMenubuttonAction)ProTest2dDisplist, NULL, DISP_LIST_DISPLAY );
    ProMenubuttonActionSet( (char*)"Disp List",(char*) "Invld DispList", 
	(ProMenubuttonAction)ProTestDisplistInvalidate, &part, 0 );
    ProMenubuttonActionSet((char*) "Disp List",(char*) "Done", 
	(ProMenubuttonAction)ProMenuDelete, NULL, 0 );
    ProMenubuttonActionSet((char*) "Disp List",(char*) "Disp List", 
	(ProMenubuttonAction)ProMenuDelete, NULL, 0 );


    /*--------------------------*\
	Run menu Disp List
    \*--------------------------*/
    status = ProMenuCreate( PROMENUTYPE_MAIN,(char*) "Disp List", &menu_id );
    TEST_CALL_REPORT( "ProMenuCreate()", "ProTest2dDisplistMenu()", 
			status, status != PRO_TK_NO_ERROR );
    if( status == PRO_TK_NO_ERROR )
    {
	status = ProMenuProcess((char*) "Disp List", &action );
	TEST_CALL_REPORT( "ProMenuProcess()", "ProTest2dDisplistMenu()", 
			    status, status != PRO_TK_NO_ERROR );
    }


    return (PRO_TK_NO_ERROR);
}



/*---------------------------------------------------------------------*\
    Function:	ProTest2dDisplist()
    Purpose:	On-button function. Manipulate a 2D diplay list.
    Returns:	0 - success; Now ignored.
\*---------------------------------------------------------------------*/
int ProTest2dDisplist( void* p_dummy, int option )
{
    ProError		status;
    int			id; /* The disp list id */
    ProMatrix		matrix;


    /*  Points are in the object's csys  */
    status = ProWindowCurrentMatrixGet( matrix );
    TEST_CALL_REPORT( "ProWindowCurrentMatrixGet()", "ProTest2dDisplist()", 
			status, status != PRO_TK_NO_ERROR );

    switch( option )
    {
      case DISP_LIST_DEL:	/* Delete */

	/* Get the display list id */
	ProUtilMsgPrint( "gen", "TEST %0s", "Enter the Display List id: " );
	status = ProMessageIntegerRead( NULL, &id );
	TEST_CALL_REPORT( "ProMessageIntegerRead()", "ProTest2dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
	if( status != PRO_TK_NO_ERROR )
	    break;

	/* Delete the specified display list */
	status = ProDisplist2dDelete( id );
	TEST_CALL_REPORT( "ProDisplist2dDelete()", "ProTest2dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
	break;


      case DISP_LIST_CREATE:	/* Create */

	/* Get the display list id */
	ProUtilMsgPrint( "gen", "TEST %0s", "Enter the Display List id: ");
	status = ProMessageIntegerRead( NULL, &id );
	TEST_CALL_REPORT( "ProMessageIntegerRead()", "ProTest2dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
	if( status != PRO_TK_NO_ERROR )
	    break;

	status = ProDisplist2dCreate( id, matrix, (ProDisplistCallback)ProTestDisplistDraw );
	TEST_CALL_REPORT( "ProDisplist2dCreate()", "ProTest2dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
                            
        /* bug in the function ProDisplist2dDisplay() */
	status = ProDisplist2dDisplay( id, matrix );
	TEST_CALL_REPORT( "ProDisplist2dDisplay()", "ProTest2dDisplist()", 
			    status, 0 );
	break;


      case DISP_LIST_DISPLAY:	/* Display */

	/* Get the display list id */
	ProUtilMsgPrint( "gen", "TEST %0s", "Enter the Display List id: ");
	status = ProMessageIntegerRead( NULL, &id );
	TEST_CALL_REPORT( "ProMessageIntegerRead()", "ProTest2dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
	if( status != PRO_TK_NO_ERROR )
	    break;
            
        /* bug in the function ProDisplist2dDisplay() */
	status = ProDisplist2dDisplay( id, matrix );
	TEST_CALL_REPORT( "ProDisplist2dDisplay()", "ProTest2dDisplist()", 
			    status, 0 );
	break;


      default:
	break;
    }

    ProWindowRepaint( PRO_VALUE_UNUSED );


    return (PRO_TK_NO_ERROR);
}



/*---------------------------------------------------------------------*\
    Function:	ProTest3dDisplistMenu()
    Purpose:	On-button function. Set up the display list menu
    Returns:	0 - success; -1 - error. Now ignored.
\*---------------------------------------------------------------------*/
int ProTest3dDisplistMenu( void* p_dummy, int int_dummy )
{
    ProError		status;
    int			menu_id;    /* The identifier of the created menu */
    int			action;
    ProMdl		part;


    /* Get current Pro/E object */
    status = ProMdlCurrentGet( &part );
    TEST_CALL_REPORT( "ProMdlCurrentGet()", "ProTest3dDisplistMenu()",
			status, status != PRO_TK_NO_ERROR);

    if( status == PRO_TK_BAD_CONTEXT )
    {
        ProUtilMsgPrint( "gen", "TEST %0s", "An object is required" );
        return (PRO_TK_GENERAL_ERROR);
    }


    /*---------------------------------*\
	Create new menu Disp List
    \*---------------------------------*/

    /* Load base menu from file */
    status = ProMenuFileRegister( (char*)"Disp List", (char*)"tkdlist.mnu", &menu_id );
    TEST_CALL_REPORT( "ProMenuFileRegister()", "ProTest3dDisplistMenu()", 
			status, status != PRO_TK_NO_ERROR );

    /* Define menu buttons */
    ProMenubuttonActionSet( (char*)"Disp List", (char*)"Cre DispList", 
				(ProMenubuttonAction)ProTest3dDisplist, NULL, DISP_LIST_CREATE );
    ProMenubuttonActionSet( (char*)"Disp List", (char*)"Del DispList", 
				(ProMenubuttonAction)ProTest3dDisplist, NULL, DISP_LIST_DEL );
    ProMenubuttonActionSet( (char*)"Disp List", (char*)"Disp DispList", 
				(ProMenubuttonAction)ProTest3dDisplist, NULL, DISP_LIST_DISPLAY );
    ProMenubuttonActionSet( (char*)"Disp List", (char*)"Invld DispList", 
				(ProMenubuttonAction)ProTestDisplistInvalidate, 
				&part, 0 );
    ProMenubuttonActionSet( (char*)"Disp List", (char*)"Done", 
				(ProMenubuttonAction)ProMenuDelete, NULL, 0 );
    ProMenubuttonActionSet( (char*)"Disp List", (char*)"Disp List", 
				(ProMenubuttonAction)ProMenuDelete, NULL, 0 );


    /*--------------------------*\
	Run menu Disp List
    \*--------------------------*/
    status = ProMenuCreate( PROMENUTYPE_MAIN, (char*)"Disp List", &menu_id );
    TEST_CALL_REPORT( "ProMenuCreate()", "ProTest3dDisplistMenu()", 
			status, status != PRO_TK_NO_ERROR );
    if( status == PRO_TK_NO_ERROR )
    {
	status = ProMenuProcess( (char*)"Disp List", &action );
	TEST_CALL_REPORT( "ProMenuProcess()", "ProTest3dDisplistMenu()", 
			    status, status != PRO_TK_NO_ERROR );
    }


    return (PRO_TK_NO_ERROR);
}



/*---------------------------------------------------------------------*\
    Function:	ProTest3dDisplist()
    Purpose:	On-button function. Manipulate a 3D diplay list.
    Returns:	0 - success; Now ignored.
\*---------------------------------------------------------------------*/
int ProTest3dDisplist( void* p_dummy, int option )
{
    ProError		status;
    int			id; /* The disp list id */
    ProMatrix		matrix;


    /*  Points are in the object's csys  */
    status = ProWindowCurrentMatrixGet( matrix );
    TEST_CALL_REPORT( "ProWindowCurrentMatrixGet()", "ProTest3dDisplist()", 
			status, status != PRO_TK_NO_ERROR );

    switch( option )
    {
      case DISP_LIST_DEL:	/* Delete */

	/* Get the display list id */
	ProUtilMsgPrint( "gen", "TEST %0s", "Enter the Display List id: " );
	status = ProMessageIntegerRead( NULL, &id );
	TEST_CALL_REPORT( "ProMessageIntegerRead()", "ProTest3dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
	if( status != PRO_TK_NO_ERROR )
	    break;

	/* Delete the specified display list */
	status = ProDisplist3dDelete( id );
	TEST_CALL_REPORT( "ProDisplist3dDelete()", "ProTest3dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
	break;


      case DISP_LIST_CREATE:	/* Create */

	/* Get the display list id */
	ProUtilMsgPrint( "gen", "TEST %0s", "Enter the Display List id: ");
	status = ProMessageIntegerRead( NULL, &id );
	TEST_CALL_REPORT( "ProMessageIntegerRead()", "ProTest3dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
	if( status != PRO_TK_NO_ERROR )
	    break;

	status = ProDisplist3dCreate( id, (ProDisplistCallback)ProTestDisplistDraw );
	TEST_CALL_REPORT( "ProDisplist3dCreate()", "ProTest3dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );

	status = ProDisplist3dDisplay( id, matrix );
	TEST_CALL_REPORT( "ProDisplist3dDisplay()", "ProTest3dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
	break;


      case DISP_LIST_DISPLAY:	/* Display */

	/* Get the display list id */
	ProUtilMsgPrint( "gen", "TEST %0s", "Enter the Display List id: ");
	status = ProMessageIntegerRead( NULL, &id );
	TEST_CALL_REPORT( "ProMessageIntegerRead()", "ProTest3dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
	if( status != PRO_TK_NO_ERROR )
	    break;

	status = ProDisplist3dDisplay( id, matrix );
	TEST_CALL_REPORT( "ProDisplist3dDisplay()", "ProTest3dDisplist()", 
			    status, status != PRO_TK_NO_ERROR );
	break;


      default:
	break;
    }

    ProWindowRepaint( PRO_VALUE_UNUSED );

    return (PRO_TK_NO_ERROR);
}



/*---------------------------------------------------------------------*\
    Function:	ProTestDisplistInvalidate()
    Purpose:	On-button function. Invalidate the 2 or 3 dimensional 
		display list
    Returns:	0 - success; -1 - error. Now ignored.
\*---------------------------------------------------------------------*/
int ProTestDisplistInvalidate( ProMdl* p_model, int int_dummy )
{
    ProError		status;


    status = ProDisplistInvalidate( *p_model );
    TEST_CALL_REPORT( "ProDisplistInvalidate()", "ProTestDisplistInvalidate()", 
			status, status != PRO_TK_NO_ERROR );

    return (status == PRO_TK_NO_ERROR) ? 0 : (PRO_TK_GENERAL_ERROR);
}



/*---------------------------------------------------------------------*\
    Function:	ProTestDisplistDraw()
    Purpose:	Call some graphics functions to create the disp list
    Returns:	PRO_TK_NO_ERROR - success;
\*---------------------------------------------------------------------*/
int ProTestDisplistDraw( void )
{

    TEST_CALL_REPORT("ProDisplistCallback()", "ProTestDisplistDraw()", (ProError)0, 0);
    
    ProTestEntityDrawMenu (NULL, 0);

    return PRO_TK_NO_ERROR;
}