找回密码
 注册
Simdroid-非首页
查看: 102|回复: 5

[二次开发] create material

[复制链接]
发表于 2010-11-17 10:44:15 | 显示全部楼层 |阅读模式 来自 北京大兴
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_sf.h>
#include <uf_part.h>
#include <uf_modl.h>
#include <uf_object_types.h>
#include <uf_disp.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);
}

#define WRITE_D(X) (write_integer_to_listing_window(#X, X))

static void write_integer_to_listing_window(char *title, int n)
{
    char
        msg[MAX_LINE_SIZE+1];

    UF_CALL(UF_UI_open_listing_window());
    sprintf(msg, "%s = %d\n", title, n);
    UF_CALL(UF_UI_write_listing_window(msg));
}

/*ARGSUSED*/
static int mask_for_bodies(UF_UI_selection_p_t select, void *type)
{
    UF_UI_mask_t
        mask = { UF_solid_type, 0, UF_UI_SEL_FEATURE_BODY };

    if (!UF_CALL(UF_UI_set_sel_mask(select,
            UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, 1, &mask)))
        return (UF_UI_SEL_SUCCESS);
    else
        return (UF_UI_SEL_FAILURE);
}

static tag_t select_a_body(char *prompt)
{
    int
        resp;
    double
        cp[3];
    tag_t
        object,
        view;

    UF_CALL(UF_UI_select_with_single_dialog("Select a body", prompt,
        UF_UI_SEL_SCOPE_WORK_PART, mask_for_bodies, NULL, &resp,
        &object, cp, &view));

    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;

}

static void do_it(void)
{
    int
        units;
    tag_t
        body,
        material,
        new_density,
        new_poisson,
        new_youngs,
        part = UF_PART_ask_display_part();
    UF_SF_material_prop_t
        property_values;

    if (UF_CALL(UF_PART_ask_units(part, &units))) return;

    if ((UF_SF_locate_named_material("MYSTEEL", &material)) ||
        (material == NULL_TAG))
    {
        if( units == UF_PART_METRIC )
        {
            UF_CALL(UF_MODL_create_exp_tag("206940000", &new_youngs));
            UF_CALL(UF_MODL_create_exp_tag( "0.288", &new_poisson));
            UF_CALL(UF_MODL_create_exp_tag("7.829e-006", &new_density));
        }
        else
        {
            UF_CALL(UF_MODL_create_exp_tag("30000091.8", &new_youngs));
            UF_CALL(UF_MODL_create_exp_tag("0.288", &new_poisson));
            UF_CALL(UF_MODL_create_exp_tag("0.000731", &new_density));
        }

        UF_CALL(UF_SF_init_matl_prop( &property_values));

        property_values.isotropic.youngs_modulus.type =
            UF_SF_MULTI_PROP_EXPRESSION;
        property_values.isotropic.youngs_modulus.multi.expression_tag =
            new_youngs;
        property_values.isotropic.poissons_ratio.type =
            UF_SF_MULTI_PROP_EXPRESSION;
        property_values.isotropic.poissons_ratio.multi.expression_tag =
            new_poisson;
        property_values.isotropic.mass_density.type =
            UF_SF_MULTI_PROP_EXPRESSION;
        property_values.isotropic.mass_density.multi.expression_tag =
            new_density;

        UF_CALL(UF_SF_create_material ("mySteel", "myMETAL",
            UF_SF_MATERIAL_ISOTROPIC, &property_values, UF_SF_MATL_IS_EDITABLE,
            &material));

        UF_SF_free_matl_prop(&property_values);
    }

    WRITE_D(material);

    while ((body = select_a_body("Apply mySteel material")) != NULL_TAG)
        UF_CALL(UF_SF_link_material(material, body));
}

/*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);
}
发表于 2011-3-10 09:17:52 | 显示全部楼层 来自 湖北武汉
Simdroid开发平台
这个函数使用时还需要什么额外的条件吗?为什么我调试这段代码时,material的最终结果一直是0,而且材料也没有创建成功。
回复 不支持

使用道具 举报

 楼主| 发表于 2011-3-10 17:22:20 | 显示全部楼层 来自 上海嘉定区
输出中间一些关键参数调试一下
回复 不支持

使用道具 举报

发表于 2011-3-16 14:04:11 | 显示全部楼层 来自 湖北武汉
if (UF_CALL((UF_SF_locate_named_material("MySteel",&material)))||(material==NULL_TAG))
这一句的作用是什么?UF_CALL显示这一句运行不过去,然后就是UF_sf_create_material这个函数有问题,别的函数执行都没有什么问题。
回复 不支持

使用道具 举报

发表于 2011-3-16 14:06:47 | 显示全部楼层 来自 湖北武汉
UF_CALL给的错误信息是乱码。
回复 不支持

使用道具 举报

发表于 2011-7-15 10:28:54 | 显示全部楼层 来自 浙江宁波
建个函数需要在fem环境下。
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-20 12:46 , Processed in 0.034543 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表