/****************************************************************************** Copyright (c) 1999 Unigraphics Solutions, Inc. Unpublished - All Rights Reserved File description: This is an external user function demonstration file for customers. Currently it is run from the command line. It takes as arguments a part name (following a -p), and an optional list of types (following a -t) separated by spaces. The program will open the specified part, and cycle through the list of given types to count the number of objects of that type, and to display all data associated with the type if the type is a point, line, arc or matrix. If the -t switch is not specified, or if the types POINT, LINE, ARC, or MATRIX are not in the list of user specified types, these types are added to the list of types to search during the cycling phase. Therefore, if no -t switch is specified, only the above 4 types will be searched for. If any of the types found within the search are a displayable type, then its display attributes are also shown. usage : ext_uf_example -p [-t [ ...] ] *******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #define MAX_TYPES 20 /* max # user specified types */ /* prototypes of local routines */ static void error_return(char *msg); static void arg_error(char *msg, char *prog_name); static void report_error(int result,char *alt_msg); static void get_args(int argc, char **argv, char *part_name, int *type_list, int *num_types); static void add_extratypes(int *type_list,int *num_types); static void show_point_info(tag_t point, int atts); static void show_line_info(tag_t line, int atts); static void show_arc_info(tag_t arc, int atts); static void show_matrix_info(tag_t matrix,int att); static void show_display_atts(tag_t object_tag); static void get_next_matrix_type(tag_t part_tag, tag_t *next_tag); static void show_attribute_info(tag_t part_tag, int num_types, int type_list[MAX_TYPES]); static void show_units(tag_t part_tag); /* called when we encounter an error. an error message is */ /* displayed, and the program is terminated. */ static void error_return(char *msg) { fprintf(stderr,"\n+++ERROR : %s.\n\n",msg); exit(1); } /* this routine does the same as the above error_return routine, */ /* except it displays the usage of the program. only called for */ /* errors occuring during argument list parsing */ static void arg_error(char *msg, char *prog_name) { fprintf(stderr,"\n+++ERROR : %s.",msg); fprintf(stderr,"\n\n usage : %s -p ",prog_name); fprintf(stderr,"[-t [ ...] ]\n\n"); exit(1); } /* this routine receives a UG error code, and uses UF_get_fail_message */ /* to translate the code into a string. this string is passed to the */ /* ret routine above. if the UG error code could NOT be translated, */ /* the alternative message which was passed in will be passed to ret. */ static void report_error(int result,char *alt_msg) { char err_message[200]; int found = UF_get_fail_message(result,err_message); if (found != 0) error_return(alt_msg); else error_return(err_message); } /* this routine parses the arguments from the command line */ static void get_args(int argc, char **argv, char *part_name, int *type_list, int *num_types) { int argc_pnt = 1; logical part_flag = FALSE, type_flag = FALSE; logical limit_exceeded = FALSE; while(argc_pnt DELETED object found :"); break; case UF_OBJ_TEMPORARY : printf("\n --> TEMPORARY object found :"); break; case UF_OBJ_CONDEMNED : printf("\n --> CONDEMNED object found :"); break; case UF_OBJ_ALIVE : printf("\n --> ALIVE object found :"); break; default : printf("\n --> Status of object : UNKNOWN"); break; } /* get number of user defined attributes */ result = UF_ATTR_count_attributes(next_tag,UF_ATTR_any,&attr_count); if (result) report_error(result,"failed in UF_ATTR_count_attributes"); /* depending on what type we are working with, show */ /* the data associated with each */ switch (type_list[i]) { case UF_point_type : show_point_info (next_tag,attr_count); break; case UF_line_type : show_line_info (next_tag,attr_count); break; case UF_circle_type: show_arc_info (next_tag,attr_count); break; case UF_matrix_type: show_matrix_info(next_tag,attr_count); break; default : printf("\n O - object of type %d ",type_list[i]); printf("with %d user defined attributes.\n",attr_count); break; } /* if the object is displayable, show its display attributes */ if (displayable) show_display_atts(next_tag); } } while (next_tag!=NULL_TAG); /* keep cycling until no more objects found */ switch (type_list[i]) { case UF_point_type : printf("\n === Number of POINTs found : %d",type_list_count); break; case UF_line_type : printf("\n === Number of LINEs found : %d",type_list_count); break; case UF_circle_type: printf("\n === Number of ARCs found : %d",type_list_count); break; case UF_matrix_type: printf("\n === Number of MATRICES found : %d",type_list_count); break; default : printf("\n === Number of type %d's found : %d",type_list[i], type_list_count); break; } printf("\n --------------------------------------------------\n"); } } /* this routine shows the units that a part works with */ static void show_units(tag_t part_tag) { int units; UF_PART_ask_units(part_tag, &units); /* translate units number into a string */ switch (units) { case UF_PART_ENGLISH : printf(" UNITS : inches\n"); break; case UF_PART_METRIC : printf(" UNITS : millimeters\n"); break; default : printf(" UNITS : unknown\n"); break; } } /***********************************************************************/ /************ MAIN ***************/ /***********************************************************************/ extern int main(int argc, char **argv) { UF_PART_load_status_t error_status; char part_name[255]; int type_list[MAX_TYPES]; int num_types=0, num_parts; int result; tag_t part_tag; /* parse command line for part name and optional list of types */ get_args(argc,argv,part_name,type_list,&num_types); /* add point, line, arc, and matrix to list of types (if not there) */ add_extratypes(type_list,&num_types); /* initialize user functions */ result = UF_initialize(); if (result) report_error(result,"failed in UF_initialize"); /* open up specified part */ result = UF_PART_open(part_name,&part_tag,&error_status); if (result) report_error(result,"failed in UF_PART_open"); num_parts = error_status.n_parts; UF_free_string_array(num_parts,error_status.file_names); printf("\n*******************************************************\n"); printf ("*** PART : %s",part_name); show_units(part_tag); printf ("*******************************************************\n"); /* cycle part, showing data */ show_attribute_info(part_tag,num_types,type_list); printf("\nEND\n"); return(0); }