Pro/TOOLKIT示例程式(八)獲取幾何元素:面
阿新 • • 發佈:2019-02-04
在Pro/TOOLKIT中,型別ProSurface表示面。ProSurface和ProGeomitem之間可以相互轉換:
- ProSurface -> ProGeomitem:ProSurfaceToGeomitem
- ProGeomitem -> ProSurface:ProGeomitemToSurface
ProSurfaceTypeGet用於獲取面的型別,面的型別有以下幾種:
- PRO_SRF_PLANE:平面。
- PRO_SRF_CYL:圓柱面。
- PRO_SRF_CONE:圓錐面
- PRO_SRF_TORUS:圓環面
- ...等等
函式ProGeomitemdataGet用於獲取面的資料,注意在用完之後要呼叫ProGeomitemdataFree來釋放資料。
ProGeomitemdata下的ProSurfacedata用於儲存面的資料,而其下 ProSurfaceshapedata srf_shape 則用於表達不同型別面的具體資料。
typedef struct geom_item_data_struct
{
ProType obj_type;
union
{
ProCurvedata *p_curve_data;
ProSurfacedata *p_surface_data;
ProCsysdata *p_csys_data;
} data;
} ProGeomitemdata;
typedef struct ptc_surf
{
......
ProSurfaceshapedata srf_shape;
......
} ProSurfacedata;
typedef union ptc_srfshape
{
ProPlanedata plane; // 平面
ProCylinderdata cylinder; // 圓柱面
ProConedata cone; // 圓錐面
ProTorusdata torus; // 圓環面
ProSrfrevdata srfrev;
......
} ProSurfaceshapedata;
示例程式碼:
// 獲取面的資料
int TestGetSurfaceData(uiCmdCmdId command,
uiCmdValue *p_value ,
void *p_push_command_data)
{
ProError err;
// 選擇面
ProSelection *sels;
int nSel = 0;
err = ProSelect("surface,datum", 1, NULL, NULL, NULL, NULL, &sels, &nSel);
if (PRO_TK_NO_ERROR != err || 1 != nSel)
{
return -1;
}
// 獲取選擇的面
ProGeomitem geomSurface;
err = ProSelectionModelitemGet(sels[0], &geomSurface);
ProSurface surface;
err = ProGeomitemToSurface(&geomSurface, &surface);
ProSrftype srfType;
err = ProSurfaceTypeGet(surface, &srfType);
// 獲取面的資料
ProGeomitemdata* geomdata;
err = ProGeomitemdataGet(&geomSurface, &geomdata);
// 根據面的型別獲取具體的資料
CStringW cstrInfo;
switch (srfType)
{
case PRO_SRF_PLANE:
{
cstrInfo = L"面的型別: 平面\n";
CStringW cstrPlaneNormalVector;
cstrPlaneNormalVector.Format(L"平面的法向量: (%.2f, %.2f, %.2f)",
geomdata->data.p_surface_data->srf_shape.plane.e3[0],
geomdata->data.p_surface_data->srf_shape.plane.e3[1],
geomdata->data.p_surface_data->srf_shape.plane.e3[2]);
cstrInfo += cstrPlaneNormalVector;
}
break;
case PRO_SRF_CYL:
{
cstrInfo = L"面的型別: 圓柱面\n";
CStringW cstrRadius;
cstrRadius.Format(L"圓柱面的半徑為: %.2f", geomdata->data.p_surface_data->srf_shape.cylinder.radius);
cstrInfo += cstrRadius;
}
break;
default:
cstrInfo = L"面的資料:親,試試自己完成!";
break;
}
MessageBoxW(NULL, cstrInfo, L"icaxdev: Sample004", MB_OK);
// 釋放資料
err = ProGeomitemdataFree(&geomdata);
return 0;
}