/*---------------------- MACRO -------------------------------------*/
/* UG_HOLE_LOG : Macro to log the calls to function inputs:
a - name of the function getting called
b - error return by the function called
*/
#define UG_HOLE_LOG( a, b ) printf(" Return value of function %s is %d\n", a, b );
/*---------------------- Function Prototypes -----------------------*/
ProError UserElemtreeElementAdd( ProElement parent_element,
ProElement child_element,
ProValueData value_data );
ProError ProDemoHoleCreate();
/*------------------------- External Data --------------------------*/
/*------------------------- Global Data ---------------------------*/
/*===============================================================*\
FUNCTION : ProDemoHoleCreate
PURPOSE : Demonstrates the creation of a straight linear hole
\*===============================================================*/
ProError ProDemoHoleCreate()
{
ProError status;
ProElement feat_elemtree;
ProElement elem_feattype;
ProElement elem_featform;
ProElement elem_hle_com;
ProElement elem_hle_type_new;
ProElement elem_hle_stan_type;
ProElement elem_diameter;
ProElement elem_hole_std_depth;
ProElement elem_hole_depth_to;
ProElement elem_hole_depth_to_type;
ProElement elem_ext_depth_to_value;
ProElement elem_ext_depth_to_ref;
ProElement elem_hole_depth_from;
ProElement elem_hole_depth_from_type;
ProElement elem_ext_depth_from_value;
ProElement elem_ext_depth_from_ref;
ProElement elem_hle_placement;
ProElement elem_hle_prim_ref;
ProElement elem_hle_pl_type;
ProElement elem_hle_dim_ref1;
ProElement elem_hle_dim_dist1;
ProElement elem_hle_dim_ref2;
ProElement elem_hle_dim_dist2;
ProValue value;
ProValueData value_data;
ProSelection *p_selection;
int n_selection;
ProFeatureCreateOptions options[] = {
PRO_FEAT_CR_DEFINE_MISS_ELEMS };
ProFeature created_feature;
ProErrorlist p_errors;
ProMdl model;
ProModelitem model_item;
ProSelection model_selection;
/* Start of Element Tree Creation */
/* Adding the root element */
status = ProElementAlloc ( PRO_E_FEATURE_TREE, &feat_elemtree );
/* Adding the element for feature type */
printf(" PRO_E_FEATURE_TYPE \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_FEATURE_TYPE, &elem_feattype );
UG_HOLE_LOG (" ProElementAlloc ", status);
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_FEAT_HOLE ;
status = UserElemtreeElementAdd( feat_elemtree,
elem_feattype, value_data );
UG_HOLE_LOG (" ProElementAlloc ", status );
/* Adding the element for feature form */
printf(" PRO_E_FEATURE_FORM \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_FEATURE_FORM , &elem_featform );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_HLE_TYPE_STRAIGHT ;
status = UserElemtreeElementAdd( feat_elemtree,
elem_featform, value_data );
UG_HOLE_LOG (" ProElementAlloc ", status );
/* Adding the common element for hole information */
printf(" PRO_E_HLE_COM \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HLE_COM, &elem_hle_com );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HLE_COM", status);
status = ProElemtreeElementAdd (feat_elemtree, NULL, elem_hle_com );
UG_HOLE_LOG (" ProElemtreeElementAdd ", status);
/* Adding the element for hole type : Straight, Standard, Sketched */
printf(" PRO_E_HLE_TYPE_NEW \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HLE_TYPE_NEW, &elem_hle_type_new );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HLE_TYPE_NEW ", status);
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_HLE_NEW_TYPE_STRAIGHT ;
status = UserElemtreeElementAdd ( elem_hle_com,
elem_hle_type_new, value_data );
UG_HOLE_LOG (" UserElemtreeElementAdd ", status);
/* Specifying the Diameter of the Hole */
printf(" PRO_E_DIAMETER \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_DIAMETER, &elem_diameter );
UG_HOLE_LOG (" ProElementAlloc PRO_E_DIAMETER ", status);
value_data.type = PRO_VALUE_TYPE_DOUBLE;
value_data.v.d = 100.0 ;//孔的直徑
status = UserElemtreeElementAdd ( elem_hle_com,
elem_diameter, value_data );
UG_HOLE_LOG (" UserElemtreeElementAdd ", status);
/* Adding an element for the Standard Depth
|--PRO_E_HOLE_STD_DEPTH
| |--PRO_E_HOLE_DEPTH_TO
| | |--PRO_E_HOLE_DEPTH_TO_TYPE
| | |--PRO_E_EXT_DEPTH_TO_VALUE
| | |--PRO_E_EXT_DEPTH_TO_REF
| |--PRO_E_HOLE_DEPTH_FROM
| |--PRO_E_HOLE_DEPTH_FROM_TYPE
| |--PRO_E_EXT_DEPTH_FROM_VALUE
| |--PRO_E_EXT_DEPTH_FROM_REF
*/
printf(" PRO_E_HOLE_STD_DEPTH \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HOLE_STD_DEPTH,
&elem_hole_std_depth );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HOLE_STD_DEPTH ", status);
status = ProElemtreeElementAdd ( elem_hle_com, NULL,
elem_hole_std_depth );
UG_HOLE_LOG (" UserElemtreeElementAdd ", status);
printf(" PRO_E_HOLE_DEPTH_TO \n", status);
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HOLE_DEPTH_TO,
&elem_hole_depth_to );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HOLE_DEPTH_TO ", status);
status = ProElemtreeElementAdd ( elem_hole_std_depth, NULL,
elem_hole_depth_to );
UG_HOLE_LOG (" ProElemtreeElementAdd ", status);
printf(" PRO_E_HOLE_DEPTH_TO_TYPE \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HOLE_DEPTH_TO_TYPE,
&elem_hole_depth_to_type );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HOLE_DEPTH_TO_TYPE ",
status);
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_HLE_STRGHT_THRU_ALL_DEPTH ;
status = UserElemtreeElementAdd ( elem_hole_depth_to,
elem_hole_depth_to_type,
value_data );
UG_HOLE_LOG (" ProElemtreeElementAdd ", status);
printf(" PRO_E_HOLE_DEPTH_FROM \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HOLE_DEPTH_FROM,
&elem_hole_depth_from );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HOLE_DEPTH_FROM ", status);
status = ProElemtreeElementAdd ( elem_hole_std_depth, NULL,
elem_hole_depth_from );
UG_HOLE_LOG (" ProElemtreeElementAdd ", status);
printf(" PRO_E_HOLE_DEPTH_FROM_TYPE \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HOLE_DEPTH_FROM_TYPE,
&elem_hole_depth_from_type );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HOLE_DEPTH_FROM_TYPE ",
status);
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_HLE_STRGHT_NONE_DEPTH ;
status = UserElemtreeElementAdd ( elem_hole_depth_from,
elem_hole_depth_from_type,
value_data);
UG_HOLE_LOG (" ProElemtreeElementAdd ", status);
/* Adding elements related to the placement details
|--PRO_E_HLE_PLACEMENT
| |--PRO_E_HLE_PRIM_REF
| |--PRO_E_HLE_PL_TYPE
| |--PRO_E_HLE_DIM_REF1
| |--PRO_E_HLE_DIM_DIST1
| |--PRO_E_HLE_DIM_REF2
| |--PRO_E_HLE_DIM_DIST2
*/
printf(" PRO_E_HLE_PLACEMENT \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HLE_PLACEMENT,
&elem_hle_placement );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HLE_PLACEMENT", status);
status = ProElemtreeElementAdd ( feat_elemtree, NULL,
elem_hle_placement );
UG_HOLE_LOG (" ProElemtreeElementAdd ", status);
printf(" PRO_E_HLE_PRIM_REF \n");
printf(" ****************** \n");
status = ProElementAlloc (PRO_E_HLE_PRIM_REF, &elem_hle_prim_ref);
UG_HOLE_LOG (" ProElementAlloc PRO_E_HLE_PRIM_REF ", status);
printf("Select a surface for Hole Placement \n");
status = ProSelect ( "datum,surface", 1, NULL, NULL, NULL, NULL,
&p_selection, &n_selection);//選擇孔放置的表面
if ( n_selection <= 0 ) return PRO_TK_GENERAL_ERROR;
UG_HOLE_LOG (" ProSelect ", status);
value_data.type = PRO_VALUE_TYPE_SELECTION;
value_data.v.r = p_selection[0] ;
status = UserElemtreeElementAdd ( elem_hle_placement,
elem_hle_prim_ref, value_data );
UG_HOLE_LOG (" UserElemtreeElementAdd ", status);
printf(" PRO_E_HLE_PL_TYPE \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HLE_PL_TYPE, &elem_hle_pl_type );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HLE_PL_TYPE ", status);
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_HLE_PL_TYPE_LIN;
status = UserElemtreeElementAdd ( elem_hle_placement,
elem_hle_pl_type, value_data );
UG_HOLE_LOG (" UserElemtreeElementAdd ", status);
printf(" PRO_E_HLE_DIM_REF1 \n");
printf(" ****************** \n");
status = ProElementAlloc (PRO_E_HLE_DIM_REF1, &elem_hle_dim_ref1 );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HLE_DIM_REF1 ", status);
printf("Select a 1st Reference for Hole Placement \n");
status = ProSelect ( "datum,surface,edge", 1, NULL, NULL, NULL,NULL,&p_selection, &n_selection);//選擇孔放置的第一個參考
if ( n_selection <= 0 ) return PRO_TK_GENERAL_ERROR;
UG_HOLE_LOG (" ProSelect ", status);
value_data.type = PRO_VALUE_TYPE_SELECTION;
value_data.v.r = p_selection[0] ;
status = UserElemtreeElementAdd ( elem_hle_placement,
elem_hle_dim_ref1, value_data );
UG_HOLE_LOG (" UserElemtreeElementAdd ", status);
printf(" PRO_E_HLE_DIM_DIST1 \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HLE_DIM_DIST1,
&elem_hle_dim_dist1 );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HLE_DIM_DIST1 ", status);
value_data.type = PRO_VALUE_TYPE_DOUBLE;
value_data.v.d = 10.0; //孔中心距離選擇的第二個參考表面正方向距離
status = UserElemtreeElementAdd (elem_hle_placement,
elem_hle_dim_dist1, value_data );
UG_HOLE_LOG (" UserElemtreeElementAdd ", status);
printf(" PRO_E_HLE_DIM_REF2 \n");
printf(" ****************** \n");
status = ProElementAlloc (PRO_E_HLE_DIM_REF2, &elem_hle_dim_ref2 );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HLE_DIM_REF2 ", status);
printf("Select a 2st Reference for Hole Placement \n");
status = ProSelect ( "datum,surface,edge", 1, NULL, NULL, NULL,NULL, &p_selection, &n_selection);//選擇第二個參考
if ( n_selection <= 0 ) return PRO_TK_GENERAL_ERROR;
UG_HOLE_LOG (" ProSelect ", status);
value_data.type = PRO_VALUE_TYPE_SELECTION;
value_data.v.r = p_selection[0] ;
status = UserElemtreeElementAdd ( elem_hle_placement,
elem_hle_dim_ref2, value_data );
UG_HOLE_LOG (" UserElemtreeElementAdd ", status);
printf(" PRO_E_HLE_DIM_DIST2 \n");
printf(" ****************** \n");
status = ProElementAlloc ( PRO_E_HLE_DIM_DIST2,
&elem_hle_dim_dist2 );
UG_HOLE_LOG (" ProElementAlloc PRO_E_HLE_DIM_DIST2 ", status);
value_data.type = PRO_VALUE_TYPE_DOUBLE;
value_data.v.d = 20.0;//孔中心距離選擇的第一個參考表面正方向距離
status = UserElemtreeElementAdd ( elem_hle_placement,
elem_hle_dim_dist2, value_data );
UG_HOLE_LOG (" UserElemtreeElementAdd ", status);
/* End of Element Tree Creation */
/* Start of Feature Creation */
status = ProMdlCurrentGet ( &model );
UG_HOLE_LOG (" ProMdlCurrentGet ", status);
status = ProMdlToModelitem( model, &model_item );
UG_HOLE_LOG (" ProMdlToModelitem ", status);
status = ProSelectionAlloc( NULL, &model_item, &model_selection );
UG_HOLE_LOG (" ProSelectionAlloc ", status);
status = ProFeatureCreate ( model_selection, feat_elemtree,
options, 1,
&created_feature, &p_errors );
UG_HOLE_LOG (" ProFeatureCreate ", status);
/* End of Feature Creation */
/* Freeing the resources */
status = ProElementFree( &feat_elemtree );
UG_HOLE_LOG (" ProElementFree ", status);
status = ProSelectionFree( &model_selection );
UG_HOLE_LOG (" ProSelectionFree ", status);
/* End of Freeing */
return ( status );
}
/*===============================================================*\
FUNCTION : UserElemtreeElementAdd
PURPOSE : Adding an element to the parent element / tree
input : parent_element, child_element, value_data
output : none
returns :
PRO_TK_NO_ERROR - Successfully added the element
PRO_TK_GENERAL_ERROR - Failed to add the element
any other return as returned by ProElemtreeElementAdd()
\*===============================================================*/
ProError UserElemtreeElementAdd( ProElement parent_element,
ProElement child_element,
ProValueData value_data )
{
ProValue value;
ProError status;
status = ProValueAlloc ( &value );
UG_HOLE_LOG (" ProValueAlloc ", status);
status = ProValueDataSet ( value, &value_data );
UG_HOLE_LOG (" ProValueDataSet ", status);
status = ProElementValueSet ( child_element, value );
UG_HOLE_LOG (" ProElementValueSet ", status);
status = ProElemtreeElementAdd ( parent_element, NULL,
child_element );
UG_HOLE_LOG (" ProElemtreeElementAdd ", status);
return ( status );
}
转载于:https://www.cnblogs.com/samyangvs05/archive/2010/04/08/1707355.html