NX二开ufun函数UF_MODL_create_section_surface(样条曲线构建截面特征)

本节主要介绍通过样条曲线及截面OPEN API结构体构建截面特征,函数名 UF_MODL_create_section_surface,效果图如下:

NX二开ufun函数UF_MODL_create_section_surface(样条曲线构建截面特征)_第1张图片

 1、函数结构

int UF_MODL_create_section_surface 

UF_MODL_secsrf_data_p_t section_surface_data,
tag_p_t section_surface

2、实例源码 

#include 
#include 
#include 
#include 
#include 
#include 

#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))

static int report( char *file, int line, char *call, int irc)
{
    if (irc)
    {
        char    messg[133];
        printf("%s, line %d:  %s\n", file, line, call);
        (UF_get_fail_message(irc, messg)) ?
            printf("    returned a %d\n", irc) :
            printf("    returned error %d:  %s\n", irc, messg);
    }
    return(irc);
}

static void do_ugopen_api(void)
{

    int knot_fix, pole_fix;
    tag_t start_tag;
    tag_t apex_tag;
    tag_t end_tag;
    tag_t spine_tag;
    tag_t feature_tag;
    double start_poles[] = {0.0, 4.0, 2.0, 1.0,
                            3.0, 4.0, 2.0, 1.0,
                            6.0, 4.0, 1.0, 1.0};

    double start_knots[] = {0.0, 0.0, 0.0,
                            1.0, 1.0, 1.0};

    double end_poles[] = {0.0, 0.0, 0.0, 1.0,
                          3.0, 0.0, 0.0, 1.0,
                          6.0, 1.0, 0.0, 1.0};

    double end_knots[] = {0.0, 0.0, 0.0,
                          1.0, 1.0, 1.0};

    double apex_poles[] = {0.0, 0.0, 2.0, 1.0,
                           3.0, 0.0, 2.0, 1.0,
                           6.0, 1.0, 1.0, 1.0};

    double apex_knots[] = {0.0, 0.0, 0.0,
                           1.0, 1.0, 1.0};

    UF_CURVE_line_t spine_coords;

    UF_MODL_secsrf_data_t section_surface;
    UF_STRING_t ss_string[2];
    UF_STRING_t apex_string;
    UF_STRING_t spine_string;

    spine_coords.start_point[0] = 6.0;
    spine_coords.start_point[1] = 4.0;
    spine_coords.start_point[2] = 0.0;

    spine_coords.end_point[0] = 0.0;
    spine_coords.end_point[1] = 4.0;
    spine_coords.end_point[2] = 0.0;

/* Create the input curves. */
    UF_CALL(UF_MODL_create_spline(3, 3, start_knots, start_poles,
                                  &start_tag,&knot_fix,&pole_fix));
    UF_CALL(UF_MODL_create_spline(3, 3, end_knots, end_poles,
                                  &end_tag, &knot_fix, &pole_fix));
    UF_CALL(UF_MODL_create_spline(3, 3, apex_knots, apex_poles,
                                  &apex_tag,&knot_fix,&pole_fix));

    UF_CALL(UF_CURVE_create_line(&spine_coords,&spine_tag));

/* Create Strings from the curves.
   Each string contains 1 curve. */

    UF_MODL_init_string_list(&ss_string[0]);
    UF_MODL_create_string_list(1,1,&ss_string[0]);
    ss_string[0].num = 1;
    ss_string[0].string[0] = 1;
    ss_string[0].dir[0] = 1;
    ss_string[0].id[0] = start_tag;

    UF_MODL_init_string_list(&ss_string[1]);
    UF_MODL_create_string_list(1,1,&ss_string[1]);
    ss_string[1].num = 1;
    ss_string[1].string[0] = 1;
    ss_string[1].dir[0] = 1;
    ss_string[1].id[0] = end_tag;

    UF_MODL_init_string_list(&apex_string);
    UF_MODL_create_string_list(1,1,&apex_string);
    apex_string.num = 1;
    apex_string.string[0] = 1;
    apex_string.dir[0] = 1;
    apex_string.id[0] = apex_tag;

    UF_MODL_init_string_list(&spine_string);
    UF_MODL_create_string_list(1,1,&spine_string);
    spine_string.num = 1;
    spine_string.string[0] = 1;
    spine_string.dir[0] = 1;
    spine_string.id[0] = spine_tag;

/* Initialize the section surface data structure. */
    UF_CALL(UF_MODL_init_section_surface (§ion_surface));

/* Populate the structure with appropriate data. */
    section_surface.create_method = UF_MODL_secsrf_ends_apex_rho;
    section_surface.polynomial_status = 0;
    section_surface.tolerance = .001;

    section_surface.control_strings[0] = &ss_string[0]; /* start */
    section_surface.control_strings[1] = &apex_string;  /* apex */
    section_surface.control_strings[2] = &ss_string[1]; /* end */
    section_surface.control_strings[3] = NULL_TAG;
    section_surface.control_strings[4] = NULL_TAG;
    section_surface.control_strings[5] = NULL_TAG;

    section_surface.spine_string = &spine_string;

    section_surface.rho_data.data_method = UF_MODL_secsrf_cubic;
    section_surface.rho_data.data_values.data_value[0] = 0.40;
    section_surface.rho_data.data_values.data_value[1] = 0.70;
    section_surface.rho_data.data_values.data_exp[0] = NULL_TAG;
    section_surface.rho_data.data_values.data_exp[1] = NULL_TAG;
    section_surface.rho_data.data_values.general_law = NULL;
    section_surface.rho_data.data_values.data_constant = 0.0;

    section_surface.tangent_faces[0] = NULL_TAG;
    section_surface.tangent_faces[1] = NULL_TAG;

    section_surface.radius_data.data_method =
                                        UF_MODL_secsrf_no_data;
    section_surface.angle_data.data_method =
                                        UF_MODL_secsrf_no_data;

/* Build the section surface. */
    UF_CALL(UF_MODL_create_section_surface(§ion_surface,
                                           &feature_tag));

/* Free all the strings. */
    UF_STRING_free_string_list(&ss_string[0]);
    UF_STRING_free_string_list(&ss_string[1]);
    UF_STRING_free_string_list(&apex_string);
    UF_STRING_free_string_list(&spine_string);

}

/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
    if (!UF_CALL(UF_initialize()))
    {
        do_ugopen_api();
        UF_CALL(UF_terminate());
    }
}

int ufusr_ask_unload(void)
{
    return (UF_UNLOAD_IMMEDIATELY);
}

3、实例分析 

1)本实例主要使用ufun函数有:

     创建样条曲线:UF_MODL_create_spline

     创建曲线:UF_CURVE_create_line

     初始化字符串列表结构:UF_MODL_init_string_list

     创建字符串列表结构:UF_MODL_create_string_list

     初始化截面数据:UF_MODL_init_section_surface

     样条曲线构建截面特征:UF_MODL_create_section_surface

2)创建样条曲线和直线很容易理解,至于字符串列表结构现在还看不明白,不过看使用方法参数和赋值都一样,我们按照实例里面用即可

3)UF_MODL_init_section_surface 和 UF_MODL_create_section_surface 是成对出现的,使用的时候先初始化再创建,ufun函数这样的情况很多不难理解

你可能感兴趣的:(二次开发Ufun,UG二开自学,c++,样条曲线,截面,剖面)