/*====================================================================*\ FILE : TestAnimation.c PURPOSE : Animation API test. HISTORY: DATE BUILD AUTHOR MODIFICATIONS 19 Jan 97 H-01-21 Alexey $$1 First version. 4 Feb 97 H-01-25 Pavel $$2 Removed #if 0 for ProMatrixInit 16-Oct-97 H-03-27 Pavel $$3 Added TEST_CALL_REPORT to action functions 16-Nov-97 I-01-26 Alexey $$4 Get rid of nested comments 26-Nov-98 I-01-27 Alexey $$5 ProTestAniObjectAdd: use asmcomppath transformation matrix for assembly components, but not for parts. \*====================================================================*/ /*--------------------------------------------------------------------*\ Pro/TOOLKIT includes \*--------------------------------------------------------------------*/ #include "ProToolkit.h" #include "ProMenu.h" #include "ProSelection.h" #include "ProModelitem.h" #include "ProMdl.h" #include "ProArray.h" #include "ProUtil.h" #include "ProAnimate.h" /*--------------------------------------------------------------------*\ Pro/DEVELOP includes \*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ C System includes \*--------------------------------------------------------------------*/ #include #include /*--------------------------------------------------------------------*\ Application includes \*--------------------------------------------------------------------*/ #include "TestError.h" #include "TestAnimation.h" #include "UtilMessage.h" #include "UtilString.h" #include "UtilCollect.h" /*--------------------------------------------------------------------*\ Macros \*--------------------------------------------------------------------*/ #define ANI_OBJECT( i, f ) (ani_obj_seq[i].anims[f]) #define PI (3.1451) #define MAX_FRAMES_NUM 30 /*--------------------------------------------------------------------*\ Data types \*--------------------------------------------------------------------*/ /*---------------------------------------------------------------*\ This structure contains information about animation objects associated with the model. Macro ANI_OBJECT(i,f) is used to get animation object handle (ProAnimObj) of the model i in the frame f. \*---------------------------------------------------------------*/ typedef struct tag_AniObjectInstance { ProMdl model; /* Handle to the animated model */ ProAsmcomppath comp_path; /* Component path of the object */ ProAnimObj anims[ MAX_FRAMES_NUM ]; /* Array of the ani objs */ } AniObjectInstance; /*--------------------------------------------------------------------*\ Application global/external data \*--------------------------------------------------------------------*/ static AniObjectInstance* ani_obj_seq = NULL; /* Array of of ani objs */ static int n_objects = 0; /* Current number of ani objs */ #if 0 static ProAnimFrame frames[ MAX_FRAMES_NUM ]; /* Animation frames */ #endif static ProAnimFrame *frames; /* Animation frames */ static int n_frames; /* Current number of frames */ /*---------------------------------------------------------------------*\ Functions declaration \*---------------------------------------------------------------------*/ ProError ProUtilSelectedMdlGet( ProSelection* , ProMdl* ); ProError ProUtilAniObjectSelect( char option[], ProSelection**, AniObjectInstance* ); ProBoolean ProUtilMdlEqual( ProMdl, ProMdl ); ProError ProUtilAniObjectFind( ProArray, AniObjectInstance ); ProError ProUtilAniObjectInstanceInit( ProSelection**, AniObjectInstance* ); ProError ProTestBatchAnimAct( ProAnimFrame, int, ProAppData ); void ProUtilRotX( double angle, ProMatrix mx ); /*---------------------------------------------------------------------*\ Function: ProTestAnimation() Purpose: Top-level function. Initialize some data, create and run ANIMATION menu, then free used resources. Returns: 0 - success; -1 - error. Now ignored. \*---------------------------------------------------------------------*/ int ProTestAnimation( void* p_dummy, int int_dummy ) { ProError status; int menu_id; /* The identifier of the created menu */ int action; /* Init the array of animation objects */ n_objects = 0; status = ProArrayAlloc( 0, sizeof(AniObjectInstance), 1, (ProArray *)&ani_obj_seq ); TEST_CALL_REPORT( "ProArrayAlloc()", "ProTestAnimation()", status, status != PRO_TK_NO_ERROR ); if( status != PRO_TK_NO_ERROR ) return -1; /* Init the array of animation frames */ n_frames = 0; status = ProArrayAlloc( 0, sizeof(ProAnimFrame), 1, (ProArray *)&frames ); TEST_CALL_REPORT( "ProArrayAlloc()", "ProTestAnimation()", status, status != PRO_TK_NO_ERROR ); if( status != PRO_TK_NO_ERROR ) return -1; status = ProArraySizeSet( (ProArray *)&frames, MAX_FRAMES_NUM ); TEST_CALL_REPORT( "ProArraySizeSet()", "ProTestAnimation()", status, status != PRO_TK_NO_ERROR ); if( status != PRO_TK_NO_ERROR ) return -1; /*-----------------------------*\ Create new menu ANIMATION \*-----------------------------*/ /* Load base menu from file */ status = ProMenuFileRegister( "Animation", "tkanim.mnu", &menu_id ); TEST_CALL_REPORT( "ProMenuFileRegister()", "ProTestAnimation()", status, status != PRO_TK_NO_ERROR ); /* Define menu buttons */ ProMenubuttonActionSet( "Animation", "Create", ProTestAnimframeCreate, NULL, 0 ); ProMenubuttonActionSet( "Animation", "Delete", ProTestAnimframeDelete, NULL, 0 ); ProMenubuttonActionSet( "Animation", "AddObject", ProTestAniObjectAdd, NULL, 0 ); ProMenubuttonActionSet( "Animation", "DeleteObject", ProTestSelAniObjectDelete, NULL, 0 ); ProMenubuttonActionSet( "Animation", "PlaySingle", ProTestSingleAnimation, NULL, 0 ); ProMenubuttonActionSet( "Animation", "PlayBatch", ProTestBatchAnimation, NULL, 0 ); ProMenubuttonActionSet( "Animation", "Animation", (ProMenubuttonAction)ProMenuDelete, NULL, 0 ); /*-----------------------*\ Run menu ANIMATION \*-----------------------*/ status = ProMenuCreate( PROMENUTYPE_MAIN, "Animation", &menu_id ); TEST_CALL_REPORT( "ProMenuCreate()", "ProTestAnimation()", status, status != PRO_TK_NO_ERROR ); if( status == PRO_TK_NO_ERROR ) { status = ProMenuProcess( "Animation", &action ); TEST_CALL_REPORT( "ProMenuProcess()", "ProTestAnimation()", status, status != PRO_TK_NO_ERROR ); } status = ProArrayFree( (ProArray *)&ani_obj_seq ); TEST_CALL_REPORT( "ProArrayFree()", "ProTestAnimation()", status, status != PRO_TK_NO_ERROR ); n_objects = 0; status = ProArrayFree( (ProArray *)&frames ); TEST_CALL_REPORT( "ProArrayFree()", "ProTestAnimation()", status, status != PRO_TK_NO_ERROR ); n_frames = 0; return 0; } /*---------------------------------------------------------------------*\ Function: ProTestAnimframeCreate() Purpose: On-button function. Initialize frames sequence structure. Returns: 0 - success; -1 - error. Now ignored. \*---------------------------------------------------------------------*/ int ProTestAnimframeCreate( void* p_dummy, int int_dummy ) { ProError status; int i; ProMatrix m_frame_view = { {1.0, 0.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, 0.0, 0.0, 1.0} }; ProVector v_x = {1.0, 0.0, 0.0}; ProVector v_y = {0.0, 1.0, 0.0}; ProVector v_z = {0.0, 0.0, 1.0}; ProPoint3d origin = {0.0, 0.0, 1.0}; /* Check animation frames */ if( n_frames > 0 ) { ProUtilMsgPrint( "gen", "TEST %0s", "Animation already exists" ); return -1; } /* Get a number of frames */ ProUtilMsgPrint( "gen", "TEST %0s", "Enter a number of frames: " ); if( !ProUtilIntGet( NULL, NULL, &n_frames ) ) n_frames = MAX_FRAMES_NUM; if( n_frames > MAX_FRAMES_NUM ) n_frames = MAX_FRAMES_NUM; /* Init the frame view matrix */ status = ProMatrixInit( v_x, v_y, v_z, origin, m_frame_view ); TEST_CALL_REPORT( "ProMatrixInit()", "ProTestAnimframeCreate()", status, status != PRO_TK_NO_ERROR ); /* Initialize the frames */ for( i=0; i=0; i-- ) ProTestAniObjectDelete( i ); /* Delete animation frames */ for( i=0; i= n_objects) ) return -1; /* Delete the animation objects */ for( i_frame=0; i_framemodel) ) != PRO_TK_NO_ERROR ) return PRO_TK_GENERAL_ERROR; /* Get a component path of the model */ status = ProSelectionAsmcomppathGet( **p_selection, &(p_ani_object->comp_path) ); TEST_CALL_REPORT( "ProSelectionAsmcomppathGet()", "ProUtilAniObjectInstanceInit()", status, status != PRO_TK_NO_ERROR ); if( status != PRO_TK_NO_ERROR ) return PRO_TK_GENERAL_ERROR; return PRO_TK_NO_ERROR; } /*---------------------------------------------------------------------*\ Function: ProUtilRotX() Purpose: Add x rotation values to the transformation matrix. Returns: None Note: Only the rotation components of the matrix are modified. \*---------------------------------------------------------------------*/ void ProUtilRotX( double angle, /* (In) The rotation angle */ ProMatrix mx ) /* (Out) The transformation matrix */ { mx[0][0] = 1.0; mx[0][1] = mx[0][2] = mx[1][0] = mx[2][0] = 0.0; mx[1][1] = mx[2][2] = cos( angle * PI / 180.0); mx[1][2] = sin( angle * PI / 180.0); mx[2][1] = - mx[1][2]; }