Pro/TOOLKIT 예제 프로그램(14) 피쳐 요소 트리

11527 단어 Pro/E 2차 개발
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;
}

좋은 웹페이지 즐겨찾기