- 积分
- 10
- 注册时间
- 2007-10-5
- 仿真币
-
- 最后登录
- 1970-1-1
|
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_part.h>
#include <uf_obj.h>
#include <uf_assem.h>
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
static int report_error( char *file, int line, char *call, int irc)
{
if (irc)
{
char err[133],
msg[133];
sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
irc, line, file);
UF_get_fail_message(irc, err);
/* NOTE: UF_print_syslog is new in V18 */
UF_print_syslog(msg, FALSE);
UF_print_syslog(err, FALSE);
UF_print_syslog("\n", FALSE);
UF_print_syslog(call, FALSE);
UF_print_syslog(";\n", FALSE);
if (!UF_UI_open_listing_window())
{
UF_UI_write_listing_window(msg);
UF_UI_write_listing_window(err);
UF_UI_write_listing_window("\n");
UF_UI_write_listing_window(call);
UF_UI_write_listing_window(";\n");
}
}
return(irc);
}
/*ARGSUSED*/
static int mask_add_faces_and_edges(UF_UI_selection_p_t select, void *type)
{
UF_UI_mask_t
mask[2] = { { UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE },
{ UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_EDGE } };
if (!UF_CALL(UF_UI_set_sel_mask(select,
UF_UI_SEL_MASK_ENABLE_SPECIFIC, 2, mask)))
return (UF_UI_SEL_SUCCESS);
else
return (UF_UI_SEL_FAILURE);
}
static tag_t select_anything(char *prompt)
{
double
cp[3];
int
resp;
tag_t
object,
view;
UF_CALL(UF_UI_set_cursor_view(0));
UF_CALL(UF_UI_select_with_single_dialog( "Select an object", prompt,
UF_UI_SEL_SCOPE_WORK_PART, mask_add_faces_and_edges, NULL, &resp,
&object, cp, &view));
UF_CALL(UF_UI_set_cursor_view(1));
if (resp == UF_UI_OBJECT_SELECTED || resp == UF_UI_OBJECT_SELECTED_BY_NAME)
{
UF_CALL(UF_DISP_set_highlight(object, 0));
return object;
}
else return NULL_TAG;
}
#define RX(X) report_simple_object_info(#X, X)
static void ask_object_type_descriptor(int type, int subtype, char *descriptor)
{
int
ii,
a_type;
char
a_line[MAX_LINE_SIZE+1],
api_dir[UF_CFI_MAX_PATH_NAME_SIZE],
*base_dir,
define[133],
*ptr,
uoth_file[UF_CFI_MAX_PATH_NAME_SIZE];
FILE
*in_file;
switch (type)
{
case UF_circle_type: /* non-std format in the header file */
strcpy(descriptor, "arc");
return;
case UF_OBJ_EXPR_TYPE:
strcpy(descriptor, "expression");
return;
case UF_OBJ_PART_TYPE:
strcpy(descriptor, "part");
return;
default:
break;
}
UF_CALL(UF_translate_variable("UGII_BASE_DIR", &base_dir));
UF_CALL(uc4575(base_dir, 100, "ugopen", api_dir));
UF_CALL(uc4575(api_dir, 0, "uf_object_types.h", uoth_file));
if ((in_file = fopen(uoth_file, "r")) == NULL)
{
strcpy(descriptor, "(uf_object_types.h not found)");
return;
}
strcpy(descriptor, "Unknown type"); /* In case its not found */
while (!feof(in_file))
{
fgets(a_line, MAX_LINE_SIZE, in_file);
if ((ii = sscanf(a_line, "#define UF_%s %d", define, &a_type)) == 2)
{
if ((ptr = strstr(define, "_type")) && (a_type == type))
{
*ptr = '\0';
strcpy(descriptor, define);
if (strcmp(define, "gfem_load")) break;
}
}
}
while (!feof(in_file))
{
fgets(a_line, MAX_LINE_SIZE, in_file);
if ((ii = sscanf(a_line, "#define UF_%s %d", define, &a_type)) == 2)
{
if (ptr = strstr(define, "_type")) break;
if (a_type == subtype)
{
if (ptr = strstr(define, "_subtype")) *ptr = '\0';
if (strstr(define, descriptor) == define)
strcpy(descriptor, define);
else
{
strcat(descriptor, "/");
strcat(descriptor, define);
}
break;
}
}
}
fclose(in_file);
while (ptr = strchr(descriptor, '_')) *ptr = ' ';
}
static void report_simple_object_info(char *what, tag_t object)
{
int
status,
subtype,
type;
tag_t
owner,
part = UF_PART_ask_display_part();
char
name[UF_OBJ_NAME_LEN + 1],
msg[133];
UF_CALL(UF_UI_open_listing_window());
sprintf(msg, "%s = %d", what, object);
UF_CALL(UF_UI_write_listing_window(msg));
if (object == NULL_TAG)
{
UF_CALL(UF_UI_write_listing_window(" (NULL_TAG)\n"));
return;
}
status = UF_OBJ_ask_status(object);
sprintf(msg, ", status: %d", status);
UF_CALL(UF_UI_write_listing_window(msg));
if (status == UF_OBJ_DELETED)
{
UF_UI_write_listing_window("\n");
return;
}
if (!UF_OBJ_ask_name(object, name))
{
UF_UI_write_listing_window(", named: ");
UF_UI_write_listing_window(name);
}
UF_CALL(UF_OBJ_ask_type_and_subtype(object, &type, &subtype));
ask_object_type_descriptor(type, subtype, msg);
UF_UI_write_listing_window(", type: ");
UF_UI_write_listing_window(msg);
if (UF_OBJ_is_object_a_promotion(object))
UF_UI_write_listing_window(", promotion");
if (UF_ASSEM_is_occurrence(object))
{
UF_CALL(UF_UI_write_listing_window(", occurrence"));
owner = UF_ASSEM_ask_part_occurrence(object);
if (owner != UF_ASSEM_ask_root_part_occ(part))
{
UF_CALL(UF_OBJ_ask_name(owner, msg));
UF_CALL(UF_UI_write_listing_window(" (from "));
UF_CALL(UF_UI_write_listing_window(msg));
UF_CALL(UF_UI_write_listing_window(")"));
}
}
UF_UI_write_listing_window("\n");
}
static void translate_gmtime(int gm_time, char *time_buff)
{
time_t
the_time;
struct tm
*time_ptr;
char
*time_format = "%d %b %Y %H:%M";
the_time = (time_t) gm_time;
time_ptr = localtime (&the_time);
strftime( time_buff, 21*sizeof(char), time_format, time_ptr);
}
static void report_objects_cre_mod_dates(tag_t object)
{
int
cre_version,
gm_time,
ii,
mod_version,
n_histories,
version;
tag_t
part;
char
*machine,
msg[UF_UI_MAX_STRING_LEN+1],
*program,
time_buff[21],
*user;
UF_PART_history_list_p_t
history_list;
UF_CALL(UF_OBJ_ask_owning_part(object, &part));
UF_CALL(UF_PART_create_history_list(&history_list));
UF_CALL(UF_PART_ask_part_history(part, history_list));
UF_CALL(UF_PART_ask_num_histories(history_list, &n_histories));
UF_CALL(UF_OBJ_ask_cre_mod_versions(object, &cre_version,
&mod_version));
for (ii = 0; ii < n_histories; ii++)
{
UF_CALL(UF_PART_ask_nth_history(history_list, ii,
&program, &user, &machine, &version, &gm_time));
if (version == cre_version) break;
}
if (ii < n_histories)
{
translate_gmtime(gm_time, time_buff);
sprintf(msg, " first created: %s\n", time_buff);
UF_CALL(UF_UI_write_listing_window(msg));
}
for (ii = 0; ii < n_histories; ii++)
{
UF_CALL(UF_PART_ask_nth_history(history_list, ii,
&program, &user, &machine, &version, &gm_time));
if (version == mod_version) break;
}
if (ii < n_histories)
{
translate_gmtime(gm_time, time_buff);
sprintf(msg, " last modified: %s\n", time_buff);
UF_CALL(UF_UI_write_listing_window(msg));
}
UF_CALL(UF_PART_delete_history_list(history_list));
}
static void do_it(void)
{
tag_t
object;
while ((object = select_anything("Report creation/modification dates"))
!= NULL_TAG)
{
RX(object);
report_objects_cre_mod_dates(object);
}
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
if (UF_CALL(UF_initialize())) return;
do_it();
UF_terminate();
}
int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
} |
|