// 根据零件上截面构成的点,在工程图中画线,对比
.h文件
std::vector<ProCsys> csyslist;
struct Note note[50];
ProGeomitem pntscon;
Pro3dPnt pntoriginal;
Pro3dPnt pntstart;
Pro3dPnt pntend;
.cpp文件
//动作函数
ProError ProFeatureVisitAction_f1(ProFeature* p_feature, ProError status, ProAppData app_data)
{
std::vector<ProFeature>* pls = (std::vector<ProFeature>*)app_data;
ProError err;
//ProMdlType p_type;
//err = ProMdlTypeGet((ProMdl)p_feature, &p_type);
ProFeattype p_type;
err = ProFeatureTypeGet(p_feature, &p_type);
if (p_type == PRO_FEAT_ZONE)
{
pls->push_back(*p_feature);
}
return PRO_TK_NO_ERROR;
}
//过滤函数
ProError ProFeatureFilterAction_f1(ProFeature* p_parameter, ProAppData app_data)
{
<span style="white-space:pre"> </span>return PRO_TK_NO_ERROR;
}
points.clear();
ProError err;
ProSolid solid = NULL;
ProDrawing drawing;
int window_id;
err = ProWindowCurrentGet(&window_id);
if (err != PRO_TK_NO_ERROR)
return;
err = ProMdlCurrentGet((ProMdl*)&drawing);
err = ProDrawingCurrentsolidGet(drawing,&solid);
int sheet1, n_sel;
ProName sheet_size;
ProView view;
ProMatrix matrix, tran;
ProVector out_line_start, out_line_end;
ProVector out_start, out_end;
ProSelection* view_sel;
err = ProSelect("dwg_view", 1, NULL, NULL, NULL, NULL, &view_sel,&n_sel);
if (err != PRO_TK_NO_ERROR)
return;
err = ProSelectionViewGet(view_sel[0], &view);
if (err != PRO_TK_NO_ERROR)
return;
ProMdl p_handle;
ProName r_mdl_name;
int p_window_id;
err = ProMdlNameGet((ProMdl)solid, r_mdl_name);
err = ProObjectwindowCreate(r_mdl_name, PRO_PART, &p_window_id); // 新开一个窗口,用来显示内存中的零件,返回当前窗口的ID
err = ProWindowActivate(p_window_id); // 激活指定窗口
err = ProWindowCurrentSet(p_window_id);
err = ProMdlLoad(r_mdl_name, PRO_MDL_PART, PRO_B_FALSE, &p_handle);
err = ProMdlDisplay(p_handle); // 显示内存中的零件
std::vector<ProFeature> featls;
err = ProSolidFeatVisit((ProSolid)p_handle, ProFeatureVisitAction_f1, ProFeatureFilterAction_f1, &featls);
if (err != PRO_TK_NO_ERROR)
return;
for (int i = 0; i < (int)featls.size(); i ++)
{
int p_n_sections, n_ids;
ProSection p_section;
ProIntlist ent_ids;
Pro2dEntdef *p_ent;
Pro2dLinedef *p_line;
ProBoolean is_projection;
err = ProFeatureNumSectionsGet(&(ProFeature)featls[i], &p_n_sections); /*!< 获得特征截面数 */
if (err != PRO_TK_NO_ERROR)
return;
err = ProFeatureSectionCopy(&(ProFeature)featls[i], /*p_n_sections - 1*/ 0, &p_section);
if (err != PRO_TK_NO_ERROR)
return;
err = ProSectionEntityIdsGet(p_section, &ent_ids, &n_ids); /*!< 截面上实体数 */
if (err != PRO_TK_NO_ERROR)
return;
for (int j = 0; j < n_ids; j ++)
{
err = ProSectionEntityGet(p_section, ent_ids[j], &p_ent);
if (err != PRO_TK_NO_ERROR)
continue;
err = ProSectionEntityIsProjection(p_section, ent_ids[j], &is_projection); /*!< 检查是否是参照,或者投影 */
if (err != PRO_TK_NO_ERROR)
continue;
if (is_projection == PRO_B_TRUE) /*!< 是参照或投影 */
{
//printf("\tEntity Is Projection\n");
continue;
}
switch (p_ent->type)
{
case PRO_2D_LINE:
p_line = (Pro2dLinedef *)p_ent;
points.push_back(*p_line);
printf("\tEnd1: [ %4.2lf, %4.2lf ]\n", p_line->end1[0], p_line->end1[1]);
printf("\tEnd2: [ %4.2lf, %4.2lf ]\n", p_line->end2[0], p_line->end2[1]);
break;
default:
break;
}
}
}
err = ProWindowCurrentSet(window_id);
if (err != PRO_TK_NO_ERROR)
return;
err = ProWindowActivate(window_id);
if (err != PRO_TK_NO_ERROR)
return;
err = ProWindowClear(p_window_id);
if (err != PRO_TK_NO_ERROR)
return;
err = ProWindowDelete(p_window_id);
if (err != PRO_TK_NO_ERROR)
return;
err = ProDrawingCurrentSheetGet(drawing, &sheet1);
if (err != PRO_TK_NO_ERROR)
return;
err = ProDrawingSheetTrfGet(drawing, sheet1, sheet_size, tran);
if (err != PRO_TK_NO_ERROR)
return;
/*!< p_handle是零件的句柄 */
err = ProViewMatrixGet(p_handle, view, matrix); /*!< 直接使用视图上的转换矩阵 */
if (err != PRO_TK_NO_ERROR)
return;
for (int i = 0; i < points.size(); i ++)
{
pntstart[0] = points[i].end1[0];
pntstart[1] = points[i].end1[1];
pntstart[2] = 0;
pntend[0] = points[i].end2[0];
pntend[1] = points[i].end2[1];
pntend[2] = 0;
//err = ProPntTrfEval(pntstart, tran, out_line_start);
//if (err != PRO_TK_NO_ERROR)
// return;
//err = ProPntTrfEval(pntend, tran, out_line_end);
//if (err != PRO_TK_NO_ERROR)
// return;
err = ProPntTrfEval(pntstart, matrix, out_start);
if (err != PRO_TK_NO_ERROR)
return;
err = ProPntTrfEval(pntend, matrix, out_end);
if (err != PRO_TK_NO_ERROR)
return;
ProVector begin_1, end_1;
begin_1[0] = out_start[0];
begin_1[1] = out_start[1];
begin_1[2] = 0;
end_1[0] = out_end[0];
end_1[1] = out_end[1];
end_1[2] = 0;
UsrLineentityCreate(drawing, begin_1, end_1, PRO_COLOR_LETTER);
}
err = ProWindowRefresh(window_id);
if (err != PRO_TK_NO_ERROR)
return;