/*====================================================================*\ FILE : TestParams.c PURPOSE : Test all ProParameter routines HISTORY.. DATE BUILD AUTHOR MODIFICATIONS 11 Mar 96 dmp $$1 Created 15-Apr-96 G-03-10 dmp $$2 Use ProTestQcrName() 19-Apr-96 G-03-10 dmp $$3 pass pointer to ProTestQcrName() 22-Apr-96 G-03-11 dmp $$4 New tests 12-May-96 G-03-13 amin $$5 Renamed ProParameterResetvalue ProParameterValueReset 22 May 96 G-03-15 amin $$6 renamed ProGeomitemSelect->ProModelitemSelect 19-Jul-96 G-03-19 mgs $$7 Added default return type to ProTestPickItem 26-Aug-96 H-01-05 Xuekai $$8 Modify due to change to ProMdl, add headers 09-Sep-96 H-01-08 Xuekai $$9 ProErr => ProError, obsolete protk.h 16-Sep-96 H-01-09 Xuekai $$10 Modify due to change in ProFeature.h 24-Sep-96 H-01-10 Xuekai $$11 Pro[Surface, Curve...]=>Opaque 02-Oct-96 H-01-11 Bojan $$12 ProSelection -> Opaque 14-Oct-96 H-01-13 Bojan $$13 Accomodated TestSetup.c 28-Oct-96 H-01-15 amin $$14 ProSelect arg list changes 25-Nov-96 H-01-19 YHC $$15 Included "UtilMessage.h". 20-Jan-97 H-01-21 Alexey $$16 Added calls ./pt_params/TestParams.c:some function 14-Mar-97 H-01-25 Pavel $$17 Modify ProTestPickItem, allow posibility to select all models. ProMdlCurrentGet called only from ProTestParams 28-Mar-97 H-01-30 Pavel $$18 File open moved to the ProTestParams ProTestParamDeleteAction created Used ProUtilCollectParameters 10-Jul-97 H-03-17 Pavel $$19 Added ProParameterDesignation... calls 15-Sep-97 H-03-22 Pavel $$20 Replace Pro/D on pro/E 22-Sep-97 H-03-23 Pavel $$21 Added more includes 07-Oct-97 H-03-26 Pavel $$22 Test ProParameterIsModified 04-Nov-98 I-01-26 Alexey $$23 Replaced some ProMenu functions by ProUtilMenu 15-Dec-98 I-01-28 mka $$24 Fix ProTestGetElemType and ProTestPickItem 31-May-99 I-03-12 mka $$25 Delete unused variable \*====================================================================*/ /*--------------------------------------------------------------------*\ Pro/TOOLKIT includes \*--------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include #include #include #include /*--------------------------------------------------------------------*\ Application includes \*--------------------------------------------------------------------*/ #include "TestError.h" #include "TestParams.h" #include "TestFiletypes.h" #include "UtilFiles.h" #include "UtilMessage.h" #include "UtilString.h" #include "UtilCollect.h" #include "UtilMenu.h" /*--------------------------------------------------------------------*\ Application macros \*--------------------------------------------------------------------*/ #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define USER_DELETE 0 #define USER_RESET 1 #define USER_RENAME 2 #define USER_DES_ADD 10 #define USER_DES_REMOVE 11 /*--------------------------------------------------------------------*\ Application data types \*--------------------------------------------------------------------*/ typedef struct { int num_params; ProParameter *param_list; } ParamList; /*--------------------------------------------------------------------*\ Application global/external data \*--------------------------------------------------------------------*/ static int ProTestListParams(ProMdl model); static int ProTestSetParam(ProMdl model); static int ProTestAddParam(ProMdl model); static int ProTestParamDeleteAction(ProMdl model, int action); static int ProTestParamDesAction(ProMdl model, int action); int ProTestShowList(ProMdl model, ProModelitem *); static FILE *fp; /*====================================================================*\ Function : ProTestParams Purpose : Display the parameters menu \*====================================================================*/ int ProTestParams(char *a, int b) { ProError status; ProMdl model; char fname[PRO_FILE_NAME_SIZE]; int id; status = ProMdlCurrentGet(&model); TEST_CALL_REPORT("ProMdlCurrentGet()", "ProTestParams()", status, status != PRO_TK_NO_ERROR); ProTestQcrName(&model, PARAMETERS, fname); fp = fopen(fname, "w"); status = ProMenuFileRegister("TkParams", "tkparams.mnu", &id); TEST_CALL_REPORT ("ProMenuFileRegister", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet("TkParams", "-ListParams", (ProMenubuttonAction)ProTestListParams, model, 0); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet("TkParams", "-SetParam", (ProMenubuttonAction)ProTestSetParam, model, 0); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet("TkParams", "-AddParam", (ProMenubuttonAction)ProTestAddParam, model, 0); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet("TkParams", "-DeleteParam", (ProMenubuttonAction)ProTestParamDeleteAction, model, USER_DELETE); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet("TkParams", "-ResetParam", (ProMenubuttonAction)ProTestParamDeleteAction, model, USER_RESET); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet("TkParams", "-RenameParam", (ProMenubuttonAction)ProTestParamDeleteAction, model, USER_RENAME); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet("TkParams", "-DesignationAdd", (ProMenubuttonAction)ProTestParamDesAction, model, USER_DES_ADD); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet("TkParams", "-DesignationDel", (ProMenubuttonAction)ProTestParamDesAction, model, USER_DES_REMOVE); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet("TkParams", "Done TkParams", (ProMenubuttonAction)ProMenuDelete, NULL, 0); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet("TkParams", "TkParams", (ProMenubuttonAction)ProMenuDelete, NULL, 0); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenuCreate(PROMENUTYPE_MAIN, "TkParams", &id); TEST_CALL_REPORT ("ProMenuCreate", "ProTestParams", status, status != PRO_TK_NO_ERROR); status = ProMenuProcess ("TkParams", &id); TEST_CALL_REPORT ("ProMenuProcess", "ProTestParams", status, status != PRO_TK_NO_ERROR); fclose(fp); return(0); } /*====================================================================*\ Function : ProTestGetElemType Purpose : Allow the user to select an element type \*====================================================================*/ static ProType ProTestGetElemType() { ProError status; int opt; static ProUtilMenuButtons elem_type[] = { {"ElementMenu", 0, TEST_CALL_PRO_MENU_DELETE}, {"Object", PRO_EXTOBJ, 0}, {"Feature", PRO_FEATURE, 0}, {"Surface", PRO_SURFACE, 0}, {"Edge", PRO_EDGE, 0}, {"", 0, 0} }; status = ProUtilMenuIntValueSelect(elem_type, &opt); if (status!=PRO_TK_NO_ERROR) opt=PRO_TYPE_INVALID; return opt; } /*====================================================================*\ Function : ProTestGetParamType Purpose : Allow the user to select a parameter type \*====================================================================*/ static ProParamvalueType ProTestGetParamType() { ProError status; int opt; static ProUtilMenuButtons param_type[] = { {"ParamTypeMenu", 0, TEST_CALL_PRO_MENU_DELETE}, {"Double", PRO_PARAM_DOUBLE, 0}, {"String", PRO_PARAM_STRING, 0}, {"Integer", PRO_PARAM_INTEGER, 0}, {"Boolean", PRO_PARAM_BOOLEAN, 0}, {"", 0, 0} }; status = ProUtilMenuIntValueSelect(param_type, &opt); TEST_CALL_REPORT ("ProUtilMenuIntValueSelect", "ProTestGetParamType", status, status != PRO_TK_NO_ERROR); return opt; } /*====================================================================*\ Function : ProTestPickItem Purpose : Allow the user to choose an item from which to generate a list of parameters \*====================================================================*/ static int ProTestPickItem( ProMdl model, /* In : current model */ ProType type, /* In : item type */ ProModelitem *p_modelitem) /* Out: selected feature, User's memory */ { int p_sel_num; ProError status = PRO_TK_BAD_INPUTS; char option[40]; ProMdlType mdltype; ProSelection *sel; if(type==PRO_TYPE_INVALID) return(FALSE); switch( type ) { case PRO_EXTOBJ: printf("Getting a Model\n"); status = ProMdlTypeGet(model, &mdltype); TEST_CALL_REPORT("ProMdlTypeGet()", "ProTestPickItem()", status, status != PRO_TK_NO_ERROR); if (mdltype == PRO_MDL_ASSEMBLY) { strcpy(option, "prt_or_asm"); } else { status = ProMdlToModelitem(model, p_modelitem); TEST_CALL_REPORT("ProMdlToModelitem()", "ProTestPickItem()", status, status != PRO_TK_NO_ERROR); return (TRUE); } break; case PRO_FEATURE: strcpy(option, "feature"); break; case PRO_EDGE: case PRO_SURFACE: strcpy(option, "edge,surface"); break; } status = ProSelect(option, 1, NULL, NULL, NULL, NULL, &sel, &p_sel_num); TEST_CALL_REPORT("ProSelect()", "ProTestPickItem()", status, status == PRO_TK_COMM_ERROR); if( status != PRO_TK_NO_ERROR ) return( FALSE ); else { status = ProSelectionModelitemGet(sel[0], p_modelitem); TEST_CALL_REPORT("ProSelectionModelitemGet()", "ProTestPickItem()", status, status != PRO_TK_NO_ERROR); return( TRUE ); } } /*====================================================================*\ Function : ProTestListParams Purpose : Generate a list of parameters for a user-selected item \*====================================================================*/ static int ProTestListParams(ProMdl model) { ProType type; ProModelitem modelitem; type = ProTestGetElemType(); if( ProTestPickItem(model, type, &modelitem) ) ProTestShowList(model, &modelitem); return( 0 ); } /*====================================================================*\ Function : ProTestShowList Purpose : Generate and display a list of parameters for a chosen item \*====================================================================*/ int ProTestShowList(ProMdl model, ProModelitem *p_modelitem) { int i, n; ProParameter *pars; ProError status; ProParamvalue value; char name[PRO_NAME_SIZE]; char astr[PRO_LINE_SIZE]; char fname[PRO_FILE_NAME_SIZE]; ProPath path; FILE *fv; ProBoolean modif = PRO_B_FALSE; status = ProUtilCollectParameters(p_modelitem, &pars); if (status!=PRO_TK_NO_ERROR) return (-1); status = ProArraySizeGet((ProArray)pars, &n); TEST_CALL_REPORT("ProArraySizeGet()", "ProTestShowList()", status, status != PRO_TK_NO_ERROR); ProTestQcrName(&model, ".inf", fname); fv = fopen(fname, "w"); fprintf(fp, "Name\t\tMod\tValType\t\tValue\n"); fprintf(fv, "Name\t\tMod\tValType\t\tValue\n"); for( i = 0; i < n; i++ ) { status = ProParameterValueGet(pars+i, &value); TEST_CALL_REPORT("ProParameterValueGet()", "ProTestShowList()", status, status != PRO_TK_NO_ERROR); status = ProParameterIsModified(pars+i, &modif); TEST_CALL_REPORT("ProParameterIsModified()", "ProTestShowList()", status, status != PRO_TK_NO_ERROR); ProWstringToString(name, pars[i].id); fprintf(fp, "%s\t%s", name, !modif ? "Yes" : "No"); fprintf(fv, "%s\t%s", name, !modif ? "Yes" : "No"); switch( value.type ) { case PRO_PARAM_DOUBLE: fprintf(fp, "\tdouble\t\t%f\n", value.value.d_val); fprintf(fv, "\tdouble\t\t%f\n", value.value.d_val); break; case PRO_PARAM_STRING: ProWstringToString(astr, value.value.s_val); fprintf(fp, "\tstring\t\t%s\n", astr); fprintf(fv, "\tstring\t\t%s\n", astr); break; case PRO_PARAM_INTEGER: fprintf(fp, "\tinteger\t\t%d\n", value.value.i_val); fprintf(fv, "\tinteger\t\t%d\n", value.value.i_val); break; case PRO_PARAM_BOOLEAN: fprintf(fp, "\tboolean\t\t%d\n", value.value.l_val); fprintf(fv, "\tboolean\t\t%d\n", value.value.l_val); break; default: fprintf(fp, "\tvoid\t\tNULL\n"); fprintf(fv, "\tvoid\t\tNULL\n"); } } ProArrayFree((ProArray*)&pars); TEST_CALL_REPORT("ProArrayFree()", "ProTestShowList()", status, status != PRO_TK_NO_ERROR); fclose(fv); ProStringToWstring(path, fname); ProInfoWindowDisplay(path, NULL, NULL); return( 0 ); } /*====================================================================*\ Function : ProTestNewParam Purpose : Create a new parameter for a selected item \*====================================================================*/ static int ProTestNewParam(ProMdl model, ProModelitem *p_modelitem ) { ProParamvalue new_value; ProParamvalueType new_value_type; ProParamvalueValue user_value; void* p_value; ProParameter new_param; ProName name; ProError status; char def_bool; char astr[PRO_NAME_SIZE*sizeof(wchar_t)]; char aname[PRO_NAME_SIZE*sizeof(wchar_t)]; new_value_type = ProTestGetParamType(); ProUtilMsgPrint("gen", "TEST %0s", "Please enter a name: "); ProUtilStringGet(name, NULL, PRO_NAME_SIZE); fprintf(fp, "Name:\t%s\n", ProWstringToString(aname, name)); switch( new_value_type ) { case PRO_PARAM_DOUBLE: ProUtilMsgPrint("gen", "TEST %0s", "Please enter a double value: "); ProUtilDoubleGet(NULL, NULL, &user_value.d_val); sprintf(astr, "Value:\t%f\n", user_value.d_val); fprintf(fp, astr); p_value = (void*)&user_value.d_val; break; case PRO_PARAM_STRING: ProUtilMsgPrint("gen", "TEST %0s", "Please enter a string value: "); ProUtilStringGet(user_value.s_val, NULL, PRO_LINE_SIZE); sprintf(astr, "Value:\t%s\n", ProWstringToString(aname, user_value.s_val)); fprintf(fp, astr); p_value = (void*)&user_value.s_val; break; case PRO_PARAM_INTEGER: ProUtilMsgPrint("gen", "TEST %0s", "Please enter a integer value: "); ProUtilIntGet(NULL, NULL, &user_value.i_val); sprintf(astr, "Value:\t%d\n", user_value.i_val); fprintf(fp, astr); p_value = (void*)&user_value.i_val; break; case PRO_PARAM_BOOLEAN: def_bool = 0; ProUtilMsgPrint("gen", "TEST %0s", "Please enter a Yes/No value[NO]: "); user_value.l_val = ProUtilYesnoGet(&def_bool); sprintf(astr, "Value:\t%d\n", user_value.l_val); fprintf(fp, astr); p_value = (void*)&user_value.l_val; break; default: return( -1 ); break; } status = ProParamvalueSet( &new_value, p_value, new_value_type ); TEST_CALL_REPORT( "ProParamvalueSet()", "ProTestNewParam()", status, status != PRO_TK_NO_ERROR ); status = ProParameterCreate(p_modelitem, name, &new_value, &new_param); TEST_CALL_REPORT("ProParameterCreate()", "ProTestNewParam()", status, status != PRO_TK_NO_ERROR); return( 0 ); } /*====================================================================*\ Function : ProTestSetParam Purpose : Allow the user to set the value of a parameter \*====================================================================*/ static int ProTestSetParam(ProMdl model) { ProName name; ProType type; ProParameter param; ProParamvalue value; ProParamvalueType value_type; ProParamvalueValue dummy_value; ProError status; char def_bool; char astr[PRO_LINE_SIZE]; char aname[PRO_NAME_SIZE*sizeof(wchar_t)]; ProModelitem sel_obj; type = ProTestGetElemType(); if( ProTestPickItem(model, type, &sel_obj) ) { ProUtilMsgPrint("gen", "TEST %0s", "Enter the name of the parameter: "); ProUtilStringGet(name, NULL, PRO_NAME_SIZE); status = ProParameterInit(&sel_obj, name, ¶m); TEST_CALL_REPORT("ProParameterInit()", "ProTestSetParams()", status, status == PRO_TK_COMM_ERROR); status = ProParameterValueGet(¶m, &value); TEST_CALL_REPORT("ProParameterValueGet()", "ProTestSetParams()", status, status == PRO_TK_COMM_ERROR); status = ProParamvalueTypeGet( &value, &value_type ); TEST_CALL_REPORT("ProParamvalueTypeGet()", "ProTestSetParams()", status, status == PRO_TK_COMM_ERROR); /* Only test call */ status = ProParamvalueValueGet( &value, value_type, &dummy_value); TEST_CALL_REPORT( "ProParamvalueValueGet()", "ProTestSetParams()", status, status == PRO_TK_COMM_ERROR); if( status == PRO_TK_NO_ERROR ) { sprintf(astr, "Name:\t%s\n", ProWstringToString(aname, name)); fprintf(fp, astr); switch( value_type ) { case PRO_PARAM_DOUBLE: ProUtilMsgPrint("gen", "TEST %0s", "Please enter a double value: "); ProUtilDoubleGet(NULL, NULL, &value.value.d_val); sprintf(astr, "Value:\t%f\n", value.value.d_val); fprintf(fp, astr); break; case PRO_PARAM_STRING: ProUtilMsgPrint("gen", "TEST %0s", "Please enter a string value: "); ProUtilStringGet(value.value.s_val, NULL, PRO_LINE_SIZE); sprintf(astr,"Value:\t%s\n", ProWstringToString(aname, value.value.s_val)); fprintf(fp, astr); break; case PRO_PARAM_INTEGER: ProUtilMsgPrint("gen", "TEST %0s", "Please enter a integer value: "); ProUtilIntGet(NULL, NULL, &value.value.i_val); sprintf(astr, "Value:\t%d\n", value.value.i_val); fprintf(fp, astr); break; case PRO_PARAM_BOOLEAN: def_bool = 0; ProUtilMsgPrint("gen", "TEST %0s", "Please enter a Yes/No value[NO]: "); value.value.l_val = ProUtilYesnoGet(&def_bool); sprintf(astr, "Value:\t%d\n", value.value.l_val); fprintf(fp, astr); break; default: return( -1 ); break; } status = ProParameterValueSet(¶m, &value); TEST_CALL_REPORT("ProParameterValueSet()", "ProTestSetParams()", status, status == PRO_TK_COMM_ERROR); } else { sprintf(astr, "Parameter '%s' does not exist\n", ProWstringToString(aname, name)); ProUtilMsgPrint("gen", "TEST %0s", astr); } } return( 0 ); } /*====================================================================*\ Function : ProTestAddParam Purpose : Add a parameter to a model item \*====================================================================*/ static int ProTestAddParam(ProMdl model) { ProType type; ProModelitem modelitem; type = ProTestGetElemType(); printf("type = %d\n", type); if( ProTestPickItem(model, type, &modelitem) ) ProTestNewParam(model, &modelitem); return( 0 ); } /*====================================================================*\ Function : ProTestParamDeleteAction Purpose : Allow the user to delete, reset or rename a parameter \*====================================================================*/ static int ProTestParamDeleteAction(ProMdl model, int action) { ProType type; ProParameter param; ProName name; ProError status; char aname[PRO_NAME_SIZE]; char astr[PRO_LINE_SIZE]; ProModelitem sel_obj; type = ProTestGetElemType(); if( ProTestPickItem(model, type, &sel_obj)) { status = ProParameterSelect(&sel_obj, ¶m); TEST_CALL_REPORT("ProParameterSelect()", "ProTestParamDeleteAction()", status, status == PRO_TK_COMM_ERROR); if( status == PRO_TK_NO_ERROR ) { ProWstringToString(aname, param.id); switch (action) { case USER_RENAME: ProUtilMsgPrint("gen", "TEST %0s", "Enter the new name of the parameter: "); ProUtilStringGet(name, NULL, PRO_NAME_SIZE); sprintf(astr, "Parameter '%s' renamed ", aname); fprintf(fp, astr); status = ProParameterRename(¶m, name); TEST_CALL_REPORT("ProParameterRename()", "ProTestParamDeleteAction()", status, status != PRO_TK_NO_ERROR); sprintf(astr, "'%s'\n", ProWstringToString(aname, name)); fprintf(fp, astr); break; case USER_RESET: sprintf(astr, "Parameter '%s' reset...\n", aname); fprintf(fp, astr); status = ProParameterValueReset(¶m); TEST_CALL_REPORT("ProParameterValueReset()", "ProTestParamDeleteAction()", status, status != PRO_TK_NO_ERROR); break; case USER_DELETE: sprintf(astr, "Parameter '%s' deleted...\n", aname); fprintf(fp, astr); status = ProParameterDelete(¶m); TEST_CALL_REPORT("ProParameterDelete()", "ProTestParamDeleteAction()", status, status != PRO_TK_NO_ERROR); break; default: fprintf(fp, "Error!\n"); break; } } } return(0); } /*====================================================================*\ Function : ProTestParamDesAction Purpose : Allow the user to add/remove designation of param \*====================================================================*/ static int ProTestParamDesAction(ProMdl model, int action) { ProType type; ProParameter param; ProError status; char aname[PRO_NAME_SIZE]; char astr[PRO_LINE_SIZE]; ProModelitem sel_obj; ProBoolean des; type = ProTestGetElemType(); if( ProTestPickItem(model, type, &sel_obj)) { status = ProParameterSelect(&sel_obj, ¶m); TEST_CALL_REPORT("ProParameterSelect()", "ProTestParamDeleteAction()", status, status == PRO_TK_COMM_ERROR); if( status == PRO_TK_NO_ERROR ) { ProWstringToString(aname, param.id); status = ProParameterDesignationVerify(¶m, &des); TEST_CALL_REPORT("ProParameterDesignationVerify()", "ProTestParamDeleteAction()", status, status != PRO_TK_NO_ERROR); switch (action) { case USER_DES_ADD: if (des) { sprintf(astr, "Parameter %s already designated", aname); break; } status = ProParameterDesignationAdd(¶m); TEST_CALL_REPORT("ProParameterDesignationAdd()", "ProTestParamDeleteAction()", status, status != PRO_TK_NO_ERROR); if (status == PRO_TK_NO_ERROR) { sprintf(astr, "Parameter %s designated", aname); } break; case USER_DES_REMOVE: if (!des) { sprintf(astr, "Parameter %s not designated", aname); break; } status = ProParameterDesignationRemove(¶m); TEST_CALL_REPORT("ProParameterDesignationRemove()", "ProTestParamDeleteAction()", status, status != PRO_TK_NO_ERROR); if (status == PRO_TK_NO_ERROR) { sprintf(astr, "Removed designation from parameter %s", aname); } break; default: strcpy(astr, "Error!"); break; } fprintf(fp, "%s\n", astr); ProUtilMsgPrint("gen", "TEST %0s", astr); } } return(0); }