标题: [二次开发] evaluate all expressions [打印本页]
作者: even2004 标题:[二次开发] evaluate all expressions 时间: 2009/09/19/07:52
#define WRITE(X) UF_UI_open_listing_window(); UF_UI_write_listing_window(X)
#define WRITE_F(X) (write_double_to_listing_window(#X, X))
static void write_double_to_listing_window(char *title, double n)
{
char
msg[UF_UI_MAX_STRING_LEN+1];
UF_CALL(UF_UI_open_listing_window());
sprintf(msg, "%s = %fn", title, n);
UF_CALL(UF_UI_write_listing_window(msg));
}
#define WRITE_L(X) (write_logical_to_listing_window(#X, X))
static void write_logical_to_listing_window(char *title, logical flag)
{
char
msg[UF_UI_MAX_STRING_LEN+1];
UF_CALL(UF_UI_open_listing_window());
if (flag)
sprintf(msg, "%s = TRUEn", title);
else
sprintf(msg, "%s = FALSEn", title);
UF_CALL(UF_UI_write_listing_window(msg));
}
/* There is no API method equvalent to these interactive options:
Tools-> Update-> Update for External Change
Tools-> Expression-> Refresh values from external spreadsheet-
Tools-> Spreadsheet-> Edit-> Update NX part
This program demonstrates a method which worked to update the model
in a test case after changing values in an external spreadsheet.
*/
static logical evaluate_all_expressions(tag_t part, logical verbose)
{
logical
something_changed = FALSE;
int
ii,
n_exp;
tag_t
*exps;
double
new_value,
old_value;
char
*full_string;
UF_CALL(UF_MODL_ask_exps_of_part(part, &n_exp, &exps));
if (n_exp > 0)+
{
for (ii = 0; ii < n_exp; ii++)
{
UF_CALL(UF_MODL_ask_exp_tag_string(exps[ii], &full_string));
if (verbose) WRITE(full_string);
if (verbose) WRITE("n");
UF_CALL(UF_MODL_ask_exp_tag_value(exps[ii], &old_value));
if (verbose) WRITE_F(old_value);
UF_CALL(UF_MODL_edit_exp(full_string));
UF_free(full_string);
UF_CALL(UF_MODL_ask_exp_tag_value(exps[ii], &new_value));
if (verbose) WRITE_F(new_value);
if (new_value != old_value) something_changed = TRUE;
}
if (verbose) WRITE_L(something_changed);
UF_free(exps);
}
return something_changed;
}
阳光精品论坛 - Powered By BMForum v5.0