/****************************************************************************** Copyright (c) 1999 Unigraphics Solutions, Inc. Unpublished - All Rights Reserved *******************************************************************************/ /* The example program does the following: Opens the part file which is specified in the command line as an input argument. Gets the list of existing suppressed features prior to update. Defines the update failure option to "Suppress". Calls UF_MODL_update_all_features to update all the features in the opened part. Restores the update failure option back to the default option (Undo). Gets the suppressed list again. Checks if there are any features suppressed during update, and prints out the names, if any. This program can be modified to abort the update process as soon as the first update failure is detected. If you wish, you may delete the code which calls UF_MODL_set_fail_option prior to and after calling UF_MODL_update_all_features. The system uses "Undo" as the default which aborts the update if the update fails. */ #include #include #include #include #include #include static int get_args(int argc, char **argv, char *part_name); static void do_it( void ); extern int main(int argc, char **argv) { int err,is_suppressed ; char partname[MAX_FSPEC_SIZE+1] ; char *feat_name ; tag_t part_tag,feature_tag ; UF_PART_load_status_t open_status ; uf_list_p_t face_list ; /* Get input arguments. */ err = get_args(argc,argv,partname) ; if (!err) { err = UF_initialize(); printf("Open part file %s...\n", partname ); err = UF_PART_open(partname,&part_tag,&open_status); if (err != 0) { printf(">>>Could not open %s\n", partname); UF_terminate(); return (1); } do_it(); err = UF_terminate(); } } static int get_args(int argc, char **argv, char *part_name) { if(argc !=2) { part_name[0] = '\0'; printf("\nThis program requires a part file name as input.\n"); printf("The syntax for this program is as follows:\n\n"); printf("\t%s \n", argv[0]); return(1); } else if ((strlen (argv[1])) > MAX_FSPEC_SIZE) { printf("Error: File name is too long."); return(1); } else { strcpy(part_name, argv[1]); return(0); } } static int ask_suppressed_features( uf_list_p_t *feature_list ) { int count = 0; UF_MODL_ask_suppress_list( feature_list ); UF_MODL_ask_list_count( *feature_list, &count ); return count; } /* * Subtract list_one from list_two * and print the left */ static void print_new_suppressed_features( uf_list_p_t list_one, uf_list_p_t list_two ) { int i, j; int count_one = 0, count_two = 0; if ( list_two != 0 ) UF_MODL_ask_list_count( list_two, &count_two ); if ( list_one != 0 ) UF_MODL_ask_list_count( list_one, &count_one ); for ( i = 0; i < count_two; i++ ) { tag_t item_in_list_two; logical pre_suppressed ; pre_suppressed = FALSE; UF_MODL_ask_list_item( list_two, i, &item_in_list_two ); for ( j = 0; j < count_one; j++) { tag_t item_in_list_one; UF_MODL_ask_list_item( list_one, j, &item_in_list_one); if ( item_in_list_one == item_in_list_two ) { pre_suppressed = TRUE; break; } } if ( !pre_suppressed ) { char *feat_name; UF_MODL_ask_feat_name( item_in_list_two, &feat_name ); printf(" %s\n", feat_name ); UF_free( feat_name ); } } } static void do_it( void ) { uf_list_p_t pre_suppress_list = 0, suppress_list = 0; int error; int pre_suppressed_count = 0; int suppressed_count = 0; printf("Ask if the part has existing suppressed features\n"); pre_suppressed_count = ask_suppressed_features( &pre_suppress_list); printf(">>>Suppressed feature count is %d\n", pre_suppressed_count ); printf("Set update failure option to Suppress\n"); error = UF_MODL_set_update_fail_option (UF_MODL_UPDATE_SUPPRESS); printf("Update all features in the current part...\n"); error = UF_MODL_update_all_features(); if (error == 0) { printf(">>>No update failure detected for features\n"); } else { char msg_buffer[133] = { 0 } ; printf(">>>*****Some feature(s) failed to update. Please examine syslog file for details\n"); UF_get_fail_message(error, msg_buffer); printf("The update failure message is\n %s\n", msg_buffer); printf("Ask again the suppressed features\n"); suppressed_count = ask_suppressed_features( &suppress_list); printf(">>>Suppressed feature count is %d\n", suppressed_count ); if ( suppressed_count > pre_suppressed_count ) { printf("The following features were suppressed during update:\n"); print_new_suppressed_features( pre_suppress_list, suppress_list ); } else printf(">>>*****Suppressed feature count reduced!!! Update result is incorrect.\n"); UF_MODL_delete_list( &suppress_list ); } UF_MODL_delete_list( &pre_suppress_list ); printf("Restore update failure option\n"); UF_MODL_set_update_fail_option (UF_MODL_UPDATE_NO_OPTION); }