Pro/TOOLKIT示例程序(十四)特征元素树

Pro/TOOLKIT创建特征时需要用到特征元素树。
特征元素树是用树状的结构形式来表达定义某个特征时所需的全部信息。
基于参照面偏移一定距离创建基准面的代码如下:

static ProError UserElemtreeElementAdd(
    ProElement parent_element,
    ProElement child_element,
    ProValueData value_data )
{
    ProValue value;
    ProError status;
    status = ProValueAlloc(&value);
    status = ProValueDataSet(value, &value_data);
    status = ProElementValueSet(child_element, value);
    status = ProElemtreeElementAdd(parent_element, NULL, child_element);
    return status;
}
//-----------------------------------------------------------------------------
// 基于参照面偏移一定距离创建基准面
// offset_surface --- 参照面
// offset_dist    --- 偏移距离
// dtm_level      --- DTM_LEVEL_ASM  创建在顶层组立
//                    DTM_LEVEL_PART 创建在参照面所在的模型
//-----------------------------------------------------------------------------
int CreateOffsetDatumPlane(ProSelection offset_surface,
                           double       offset_dist,
                           int          dtm_level)
{
    ProError         status;
    ProElement       elem_tree, elem_ftype, elem_consts, elem_offset;
    ProElement       elem_const_type, elem_offset_ref, elem_offset_dist;
    ProValueData     value_data;
    ProModelitem     surf_modelitem, model_modelitem;
    ProSelection     mdl_sel;
    ProFeature       feature;
    ProErrorlist     errors;
    ProAsmcomppath   p_cmp_path;

    /*----------------------------------------------------------------*\
    Allocate the root element of the tree
    \*----------------------------------------------------------------*/
    status = ProElementAlloc(PRO_E_FEATURE_TREE, &elem_tree);

    /*----------------------------------------------------------------*\
    Allocate the feature type element. Add it to the element tree.
    \*----------------------------------------------------------------*/
    status = ProElementAlloc(PRO_E_FEATURE_TYPE, &elem_ftype);
    value_data.type = PRO_VALUE_TYPE_INT;
    value_data.v.i = PRO_FEAT_DATUM;
    status = UserElemtreeElementAdd(elem_tree, elem_ftype, value_data);

    /*----------------------------------------------------------------*\
    Allocate the constraints element. Add it to the element tree.
    \*----------------------------------------------------------------*/
    status = ProElementAlloc(PRO_E_DTMPLN_CONSTRAINTS, &elem_consts);
    status = ProElemtreeElementAdd(elem_tree, NULL, elem_consts);

    /*----------------------------------------------------------------*\
    Allocate the constraint element. Add it under constraints element.
    \*----------------------------------------------------------------*/
    status = ProElementAlloc(PRO_E_DTMPLN_CONSTRAINT, &elem_offset);
    status = ProElemtreeElementAdd(elem_consts, NULL, elem_offset);

    /*----------------------------------------------------------------*\
    Allocate the constraint type element. Add it under the
    constraint element.
    \*----------------------------------------------------------------*/
    status = ProElementAlloc(PRO_E_DTMPLN_CONSTR_TYPE, &elem_const_type);
    value_data.type = PRO_VALUE_TYPE_INT;
    value_data.v.i = PRO_DTMPLN_OFFS;   
    status = UserElemtreeElementAdd(elem_offset, elem_const_type, value_data);

    /*----------------------------------------------------------------*\
    Allocate the constraint reference element. Add it under the
    constraint element.
    \*----------------------------------------------------------------*/
    status = ProElementAlloc(PRO_E_DTMPLN_CONSTR_REF, &elem_offset_ref);
    value_data.type = PRO_VALUE_TYPE_SELECTION;
    value_data.v.r = offset_surface;
    status = UserElemtreeElementAdd(elem_offset, elem_offset_ref, value_data);

    /*----------------------------------------------------------------*\
    Allocate the reference offset value element. Add it under the
    constraint element.
    \*----------------------------------------------------------------*/
    status = ProElementAlloc (PRO_E_DTMPLN_CONSTR_REF_OFFSET, &elem_offset_dist);
    value_data.type = PRO_VALUE_TYPE_DOUBLE;
    value_data.v.d = offset_dist;
    status = UserElemtreeElementAdd(elem_offset, elem_offset_dist, value_data);

    /*----------------------------------------------------------------*\
    Get the assembly component path to the part that contains the
    offset surface.
    \*----------------------------------------------------------------*/
    status = ProSelectionAsmcomppathGet(offset_surface, &p_cmp_path);

    switch (dtm_level)
    {
    case DTM_LEVEL_ASM:
        /*----------------------------------------------------------*\
        Get a ProModelitem handle to the root assembly 
        \*----------------------------------------------------------*/
        status = ProMdlToModelitem(p_cmp_path.owner, &model_modelitem);
        /*----------------------------------------------------------*\
        Allocate a ProSection object for the root assembly.
        \*----------------------------------------------------------*/
        status = ProSelectionAlloc(NULL, &model_modelitem, &mdl_sel);
        break;

    case DTM_LEVEL_PART:
        /*----------------------------------------------------------*\
        Get a ProModelitem handle to the selected surface.
        \*----------------------------------------------------------*/
        status = ProSelectionModelitemGet(offset_surface, &surf_modelitem);
        /*----------------------------------------------------------*\
        Get a ProModelitem to the owner of the selected surface.
        \*----------------------------------------------------------*/
        status = ProMdlToModelitem(surf_modelitem.owner, &model_modelitem);
        /*----------------------------------------------------------*\
        Allocate a ProSection object for the part to which the
        selected surface belongs.
        \*----------------------------------------------------------*/
        status = ProSelectionAlloc(&p_cmp_path, &model_modelitem, &mdl_sel);
        break;

    default:
        return 0;
    }

    /*----------------------------------------------------------------*\
    Create the datum plane.
    \*----------------------------------------------------------------*/
    status = ProFeatureCreate(mdl_sel, elem_tree, NULL, 0, &feature, &errors);

    /*----------------------------------------------------------------*\
    Free data
    \*----------------------------------------------------------------*/
    status = ProElementFree(&elem_tree);
    status = ProSelectionFree(&mdl_sel);

    return status;
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值