Example #1
0
// 草绘裁剪
void OnTrimBySketchActFn()
{
	/*if (!QuickCheckValidLicense(SMART_PROFESSIONAL))
		return;*/

	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	DestroyAllDialog();
	CancelSelectDialog();
	Sleep(50);

	ProError status;
	ProMdl pMdl = GetCurrentMdl();
	if (pMdl == NULL)
	{
		MessageBox(NULL, L"当前环境未发现模型!", L"提示", MB_OK|MB_ICONWARNING);
		return;
	}
	
	// 选择草绘
	vector<ProSelection> arrSel;
	ShowMessageTip(L"Tips.选择草绘特征...");
	while (SelectObject(arrSel, "feature"))
	{
		// 检查是否为草绘曲线
		ProFeature featSketch;
		status = ProSelectionModelitemGet(arrSel[0], &featSketch);
		ProFeattype featType;
		status = ProFeatureTypeGet(&featSketch, &featType);
		if (featType == PRO_FEAT_CURVE)
		{
			ProAsmcomppath acomppath;
			ProSelectionAsmcomppathGet(arrSel[0], &acomppath);

			ProSelection selQuilt;	// 待裁剪的平面
			BOOL bGetQuilt = FALSE;

			// 获取草绘曲线所在的平面
			ProElement elemTreeCurve = NULL;
			ProFeatureElemtreeExtract(&featSketch, NULL, PRO_FEAT_EXTRACT_NO_OPTS, &elemTreeCurve);
			ProElempathItem pathItemType[1];
			pathItemType[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
			pathItemType[0].path_item.elem_id = PRO_E_CURVE_TYPE;
			ProElempath elemPathCurveType;
			ProElempathAlloc(&elemPathCurveType);
			ProElempathDataSet(elemPathCurveType, pathItemType, 1);
			ProElement elemType;
			status = ProElemtreeElementGet(elemTreeCurve, elemPathCurveType, &elemType);
			if (status == PRO_TK_NO_ERROR)
			{
				ProValue valType;
				status = ProElementValueGet(elemType, &valType);
				ProValueData valdataType;
				status = ProValueDataGet(valType, &valdataType);
				if (valdataType.v.i == PRO_CURVE_TYPE_SKETCHED)
				{
					// 确定为草绘曲线,进而获取草绘平面
					ProElempathItem pathItemSketchPlane[3];
					pathItemSketchPlane[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
					pathItemSketchPlane[0].path_item.elem_id = PRO_E_STD_SECTION;
					pathItemSketchPlane[1].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
					pathItemSketchPlane[1].path_item.elem_id = PRO_E_STD_SEC_SETUP_PLANE;
					pathItemSketchPlane[2].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
					pathItemSketchPlane[2].path_item.elem_id = PRO_E_STD_SEC_PLANE;
					ProElempath elemPathPlane;
					ProElempathAlloc(&elemPathPlane);
					ProElempathDataSet(elemPathPlane, pathItemSketchPlane, 3);
					ProElement elemPlane;
					status = ProElemtreeElementGet(elemTreeCurve, elemPathPlane, &elemPlane);
					if (status == PRO_TK_NO_ERROR)
					{
						ProValue valPlane;
						status = ProElementValueGet(elemPlane, &valPlane);
						ProValueData valdataPlane;
						status = ProValueDataGet(valPlane, &valdataPlane);
						ProGeomitem itemSurf;
						ProSelectionModelitemGet(valdataPlane.v.r, &itemSurf);
						ProSurface surf;
						ProGeomitemToSurface(&itemSurf, &surf);

						// 获取面所在面组
						ProQuilt quilt;
						status = ProSurfaceQuiltGet(ProMdlToSolid(pMdl), surf, &quilt);
						if (status == PRO_TK_NO_ERROR)
						{
							ProGeomitem itemQuilt;
							status = ProQuiltToGeomitem(ProMdlToSolid(pMdl), quilt, &itemQuilt);
							status = ProSelectionAlloc(&acomppath, &itemQuilt, &selQuilt);
							bGetQuilt = TRUE;
						}
					}
				}
			}
			
			if (!bGetQuilt)
			{
				ShowMessageTip(L"Tips.草绘的放置面非可裁剪面,请手动选择需裁剪的面...");
				// 手动选取待裁剪的面
				vector<ProSelection> arrSelSrf;
				if (SelectObject(arrSelSrf, "dtmqlt"))
				{
					ProSelectionCopy(arrSelSrf[0], &selQuilt);
				}
				else
				{
					break;
				}
			}
	
			// 遍历特征,获取特征中的全部复合曲线
			vector<ProGeomitem> arrItemCurves;
			status = ProFeatureGeomitemVisit(&featSketch, PRO_CURVE, FeatureGeomsGetAction, NULL, &arrItemCurves);
			vector<int> arrFeatID;
			for (int i=0; i<arrItemCurves.size(); i++)
			{
				ProCurve curve;
				status = ProGeomitemToCurve(&arrItemCurves[i], &curve);
				// 检查是否为复合曲线
				ProEnttype curveType;
				status = ProCurveTypeGet(curve, &curveType);
				if (curveType == PRO_ENT_CMP_CRV)
				{
					// 进行裁剪
					ProSelection selCurve;
					status = ProSelectionAlloc(&acomppath, &arrItemCurves[i], &selCurve);
					int nFeatID = TrimQuiltByCurve(pMdl, selQuilt, selCurve, PRO_EDGE_SAME_DIRECTION);
					if (nFeatID > 0)
					{
						// 创建成功,记录特征ID
						arrFeatID.push_back(nFeatID);

						// 第8步:提示是否反向或继续修剪
						CDlgConfirm dlg;
						while (1)
						{
							int nResult = (int)dlg.DoModal();
							if (nResult == IDOK)
							{
								break;
							}
							else if (nResult == IDRETRY) 
							{
								// 修改裁剪方向
								ProFeature feat;
								feat.id = nFeatID;
								feat.type = PRO_FEATURE;
								feat.owner = pMdl;
								ReverseTrimDirection(feat);
							}
							else
							{
								InvalidateDrawing();
								ProMessageClear();
								return;
							}
						}
					}
				}
			}
			// 合并成组
			CreateFeatGroup(pMdl, arrFeatID, L"包覆面_裁剪");
			break;
		}
		else
		{
			// 
			MessageBox(NULL, L"所选特征非草绘特征,请重新选择!", L"提示", MB_OK);
		}
	}

	InvalidateDrawing();
	ProMessageClear();
}
Example #2
0
/*====================================================================*\
    FUNCTION :	ProUtilFeatureDump()
    PURPOSE  :	To write a decription of a feature to a text file
\*====================================================================*/
void ProUtilFeatureDump(
    ProModelitem *feature,
    FILE *fp)
{
    ProError status;
    ProSolid owner;
    ProAsmcomppath path;
    ProModelitem modelitem;    
    int n_children, c, n_parents, p;
    ProPatternStatus pstatus;
    ProGrppatternStatus gpstatus;
    ProFeatStatus fstatus;
    ProGroupStatus gstatus;
    ProSelection selection;
    char model_name[PRO_NAME_SIZE], model_type[PRO_NAME_SIZE];
    int m;
    ProFeattype ftype;
    char ftype_str[PRO_NAME_SIZE];
    int *children_ids, *parents_ids;
    ProBoolean is_nc_seq;
    ProWVerstamp stamp;
    char* p_stamp_string;

/*--------------------------------------------------------------------*\
    Check the feature owner
\*--------------------------------------------------------------------*/
    status = ProModelitemMdlGet(feature, (ProMdl *) &owner);
    TEST_CALL_REPORT("ProModelitemMdlGet()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
    ProUtilModelnameGet((ProMdl*)&owner, model_name,  model_type);
    ProTKFprintf(fp,"Owner     : %s.%s\n", model_name, model_type);

/*--------------------------------------------------------------------*\
    Check the feature owner
\*--------------------------------------------------------------------*/
    status = ProFeatureSolidGet(feature, &owner);
    TEST_CALL_REPORT("ProFeatureSolidGet()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
    ProUtilModelnameGet((ProMdl*)&owner, model_name,  model_type);
    ProTKFprintf(fp,"Sld Owner : %s.%s\n", model_name, model_type);

/*--------------------------------------------------------------------*\
    Get the list of children of the selected feature
\*--------------------------------------------------------------------*/
    status = ProFeatureChildrenGet(feature, &children_ids, &n_children);
    TEST_CALL_REPORT("ProFeatureChildrenGet()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
    ProTKFprintf(fp, "Children : ");
    for(c=0; c<n_children; c++)
	ProTKFprintf(fp,"%d ", children_ids[c]);
    ProTKFprintf(fp,"\n");

/*--------------------------------------------------------------------*\
    Get the list of parents of the selected feature
\*--------------------------------------------------------------------*/
    status = ProFeatureParentsGet(feature, &parents_ids, &n_parents);
    TEST_CALL_REPORT("ProFeatureParentsGet()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
    ProTKFprintf(fp, "Parents  : ");
    for(p=0; p<n_parents; p++)
	ProTKFprintf(fp,"%d ", parents_ids[p]);
    ProTKFprintf(fp,"\n");

/*--------------------------------------------------------------------*\
    Get the version stamp of the specified feature
\*--------------------------------------------------------------------*/
    status = ProVerstampAlloc( &stamp );
    TEST_CALL_REPORT("ProVerstampAlloc()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
    status = ProFeatureVerstampGet( feature, &stamp );
    TEST_CALL_REPORT("ProFeatureVerstampGet()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
    status = ProVerstampStringGet( stamp, &p_stamp_string );
    TEST_CALL_REPORT("ProVerstampStringGet()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
    
    ProTKFprintf( fp,"Version stamp: %s\n", p_stamp_string );

    status = ProVerstampStringFree( &p_stamp_string );
    TEST_CALL_REPORT("ProVerstampStringFree()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
    status = ProVerstampFree( &stamp );
    TEST_CALL_REPORT("ProVerstampFree()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);

/*--------------------------------------------------------------------*\
    Get the feature status
\*--------------------------------------------------------------------*/
    status = ProFeatureStatusGet(feature, &fstatus);
    TEST_CALL_REPORT("ProFeatureStatusGet()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
    ProTKFprintf(fp, "FEATURE STATUS       ");
    switch(fstatus)
    {
    case PRO_FEAT_INVALID:
	ProTKFprintf(fp, "Invalid\n");
	break;
    case PRO_FEAT_ACTIVE:
	ProTKFprintf(fp, "Active\n");
	break;
    case PRO_FEAT_INACTIVE:
	ProTKFprintf(fp, "Inactive\n");
	break;
    case PRO_FEAT_FAMTAB_SUPPRESSED:
	ProTKFprintf(fp, "Famtab suppressed\n");
	break;
    case PRO_FEAT_SIMP_REP_SUPPRESSED:
	ProTKFprintf(fp,"Simprep suppressed\n");
	break;
    case PRO_FEAT_PROG_SUPPRESSED:
	ProTKFprintf(fp,"Pro/PROGRAM suppressed\n");
	break;
    case PRO_FEAT_SUPPRESSED:
	ProTKFprintf(fp, "Suppressed\n");
	break;
    case PRO_FEAT_UNREGENERATED:
	ProTKFprintf(fp, "Unregenerated\n");
	break;
    default:
	ProTKFprintf(fp, "**UNKNOWN**\n");
	break;
    }

/*--------------------------------------------------------------------*\
    Get the group status of the feature
\*--------------------------------------------------------------------*/
    status = ProFeatureGroupStatusGet( feature, &gstatus );
    TEST_CALL_REPORT("ProFeatureGroupStatusGet()", "ProUtilFeatureDump()",
                                        status, status != PRO_TK_NO_ERROR);
    ProTKFprintf(fp, "GROUP STATUS       ");
    switch(gstatus)
    {
    case PRO_GROUP_INVALID:
	ProTKFprintf(fp, "Invalid\n");
	break;
    case PRO_GROUP_NONE:
	ProTKFprintf(fp, "None\n");
	break;
    case PRO_GROUP_MEMBER:
	ProTKFprintf(fp, "Group member\n");
	break;
    default:
	ProTKFprintf(fp, "**UNKNOWN**\n");
	break;
    }

/*--------------------------------------------------------------------*\
    Get the pattern status of the feature
\*--------------------------------------------------------------------*/
    status = ProFeaturePatternStatusGet(feature, &pstatus);
    TEST_CALL_REPORT("ProFeaturePatternStatusGet()", "ProUtilFeatureDump()",
                                        status, status != PRO_TK_NO_ERROR);
    status = ProFeatureGrppatternStatusGet(feature, &gpstatus);
    TEST_CALL_REPORT("ProFeatureGrppatternStatusGet()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
    ProTKFprintf(fp, "PATTERN STATUS       ");
    switch(pstatus)
    {
    case PRO_PATTERN_LEADER:
	ProTKFprintf(fp, "Leader of a feature pattern\n");
	break;
    case PRO_PATTERN_MEMBER:
	ProTKFprintf(fp, "Member of a feature pattern\n");
	break;
    default:
	break;
    }
    switch(gpstatus)
    {
    case PRO_GRP_PATTERN_LEADER:
        ProTKFprintf(fp, "Leader of a group pattern\n");
        break;
    case PRO_GRP_PATTERN_MEMBER:
        ProTKFprintf(fp, "Member of a group pattern\n");
        break;
    case PRO_GRP_PATTERN_NONE:
        if (pstatus == PRO_PATTERN_NONE)
            ProTKFprintf(fp, "Not a pattern member\n");
        break;
    default:
        break;
    }

/*--------------------------------------------------------------------*\
    Get elements info. 
\*--------------------------------------------------------------------*/
    ProUtilFeatureElementsDump( feature, fp);

/*--------------------------------------------------------------------*\
    Find whether the feature is an NC sequence
\*--------------------------------------------------------------------*/
    status = ProFeatureIsNcseq(feature, &is_nc_seq);

   if ( is_nc_seq == PRO_B_TRUE )
	ProTKFprintf(fp, "Feature is an NC Sequence\n");
    TEST_CALL_REPORT("ProFeatureIsNcseq()", "ProUtilFeatureDump()",
				PRO_TK_NO_ERROR, status != PRO_TK_NO_ERROR);

/*--------------------------------------------------------------------*\
    Find out whether the feature is created in an assembly
\*--------------------------------------------------------------------*/
    status = ProFeatureSelectionGet(feature, &selection);
    TEST_CALL_REPORT("ProFeatureSelectionGet()", "ProUtilFeatureDump()",
				    status, ((status != PRO_TK_NO_ERROR) &&
					     (status != PRO_TK_BAD_CONTEXT) &&
					     (status != PRO_TK_E_NOT_FOUND)));
    if(!(status == PRO_TK_BAD_CONTEXT))
    if(status == PRO_TK_E_NOT_FOUND)
    {
	ProTKFprintf(fp,"ASSEMBLY REFERENCES :\n");
	ProTKFprintf(fp," (Assembly is not in session)\n");
    }
    else if(status == PRO_TK_NO_ERROR)
    {
	ProTKFprintf(fp,"ASSEMBLY REFERENCES :\n");
	
	status = ProSelectionAsmcomppathGet(selection, &path);
	TEST_CALL_REPORT("ProSelectionAsmcomppathGet()", "ProUtilFeatureDump()",
			 status, status != PRO_TK_NO_ERROR);

	status = ProSelectionModelitemGet(selection, &modelitem);
	TEST_CALL_REPORT("ProSelectionModelitemGet()", "ProUtilFeatureDump()",
			 status, status != PRO_TK_NO_ERROR);
	
/*--------------------------------------------------------------------*\
	Assembly name
\*--------------------------------------------------------------------*/

	ProUtilModelnameGet((ProMdl*)&path.owner, model_name,  model_type);
	ProTKFprintf(fp,"    Owning model : %s.%s\n", model_name, model_type);

/*--------------------------------------------------------------------*\
	Feature id and type
\*--------------------------------------------------------------------*/
	status = ProFeatureTypeGet(&modelitem, &ftype);
	TEST_CALL_REPORT("ProFeatureTypeGet()", "ProUtilFeatureDump()",
					status, status != PRO_TK_NO_ERROR);
	ProUtilFeattypeStr(ftype, ftype_str);
	ProTKFprintf(fp,"    Feature      : %d, type %s\n", modelitem.id, ftype_str);

/*--------------------------------------------------------------------*\
	Component id table
\*--------------------------------------------------------------------*/
	if (path.table_num > 0)
	{
	    ProTKFprintf(fp,"    comp_id_table   ");	    
	    for(m=0; m<path.table_num; m++)
	        ProTKFprintf(fp,"%d", path.comp_id_table[m]);
	    ProTKFprintf(fp, "\n");
	}
	
    }
}