double CSDMdlMachChamferAngCheck::GetChamferLeg2Val(ProFeature *pFeature, int SetNum)
{

	ProError status;

	ProValue                value;
	ProValueData            value_data;

	ProElempath             Leg2_path;
	ProElempathItem         Leg2_pathItem[6];//参数2

	Leg2_pathItem[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
	Leg2_pathItem[0].path_item.elem_id = PRO_E_RNDCH_SETS;
	Leg2_pathItem[1].type = PRO_ELEM_PATH_ITEM_TYPE_INDEX;
	Leg2_pathItem[1].path_item.elem_id = SetNum;
	Leg2_pathItem[2].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
	Leg2_pathItem[2].path_item.elem_id = PRO_E_RNDCH_RADII;
	Leg2_pathItem[3].type = PRO_ELEM_PATH_ITEM_TYPE_INDEX;
	Leg2_pathItem[3].path_item.elem_id = 0;
	Leg2_pathItem[4].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
	Leg2_pathItem[4].path_item.elem_id = PRO_E_RNDCH_LEG2;
	Leg2_pathItem[5].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
	Leg2_pathItem[5].path_item.elem_id = PRO_E_RNDCH_LEG_VALUE;

	status = ProElempathAlloc (&Leg2_path);
	status = ProElempathDataSet (Leg2_path, Leg2_pathItem, 6);

	status = ProFeatureElemValueGet(pFeature,Leg2_path,&value);

	status = ProValueDataGet (value, &value_data);

	return value_data.v.d;

}
// 检查壁特征,获取折弯半径
BOOL CSDMdlMachBendRadiusCheck::GetBendRadius(ProFeature *pFeature, double& dRadius)
{
	ProError status;

	ProElempath pElemPath = NULL;
	ProValue pValue = NULL;
	ProValueData value_data;

	ProElempathItem pathItems[2];
	pathItems[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
	pathItems[0].path_item.elem_id = PRO_E_SMT_FILLETS;
	pathItems[1].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
	pathItems[1].path_item.elem_id = PRO_E_SMT_FILLETS_VALUE;

	status = ProElempathAlloc (&pElemPath);
	status = ProElempathDataSet (pElemPath, pathItems, 2);
	status = ProFeatureElemValueGet(pFeature, pElemPath, &pValue);
	if (status != PRO_TK_NO_ERROR)
	{
		status = ProElempathFree(&pElemPath);
		return FALSE;
	}
	status = ProValueDataGet(pValue, &value_data);
	dRadius = value_data.v.d;
	status = ProElempathFree(&pElemPath);

	return TRUE;
}
// 特征过滤函数 判断哪些特征需要检查
ProError CSDMdlAttrFeaSystemCheck::FeatureNameFilter(ProFeature* pFeature, ProAppData app_data)
{
	NameFeaVisitData &visitData=*(NameFeaVisitData*)app_data;
	
	// 检查特征类型
	ProFeattype feaType;
	ProFeatureTypeGet(pFeature, &feaType);
	if(feaType!=visitData.nFeaType)
	{
		return PRO_TK_CONTINUE;
	}

	ProError status;
	// 检查特征子类型(不同类型特征检查方式不一样)
	switch (feaType)
	{
	case PRO_FEAT_GEOM_COPY:	// 区分复制几何、发布几何、收缩包络
		{
			ProElement pro_e_feature_tree = NULL;
			ProFeatureElemtreeExtract(pFeature, NULL, PRO_FEAT_EXTRACT_NO_OPTS, &pro_e_feature_tree);
			ProElempathItem path_items[1];
			path_items[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
			path_items[0].path_item.elem_id = PRO_E_CG_FEAT_SUB_TYPE;
			ProElempath path;
			ProElempathAlloc(&path);
			ProElempathDataSet(path, path_items, 1);
			ProElement pElement = NULL;
			ProElemtreeElementGet(pro_e_feature_tree, path, &pElement);
			ProValue pValue = NULL;
			status = ProElementValueGet(pElement, &pValue);
			ProValueData valueData;
			status = ProValueDataGet(pValue, &valueData);
			ProElementFree(&pro_e_feature_tree);
			if (valueData.v.i != visitData.nSubType)
				return PRO_TK_CONTINUE;
		}
		break;
	default:
		break;
	}

	return PRO_TK_NO_ERROR;
}
Пример #4
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();
}
// 检查倒角特征,若倒角角度值小于输入值,返回FALSE,否则返回TRUE
BOOL CSDMdlMachChamferAngCheck::CheckChamferFeature(ProFeature *pFeature,  CString strAngle)
{
	ProError status;

	double Leg1Val;
	double Leg2Val;

	ProElempathItem pathItems[3];
	pathItems[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
	pathItems[0].path_item.elem_id = PRO_E_RNDCH_SETS;
	pathItems[1].type = PRO_ELEM_PATH_ITEM_TYPE_INDEX;
	pathItems[1].path_item.elem_index = 0;
	pathItems[2].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
	pathItems[2].path_item.elem_id = PRO_E_RNDCH_DIMENSIONAL_SCHEMA;

	CStringArray arrChamferAng;
	CStringToCStringArray(strAngle, arrChamferAng);

	ProElempath pElemPath = NULL;
	ProValue pValue = NULL;
	ProValueData value_data;
	for (int i = 0;; i++)
	{
		status = ProElempathAlloc (&pElemPath);
		pathItems[1].path_item.elem_index = i;
		status = ProElempathDataSet (pElemPath, pathItems, 3);

		status = ProFeatureElemValueGet(pFeature, pElemPath, &pValue);
		if (status == PRO_TK_NO_ERROR)
		{
			status = ProValueDataGet(pValue, &value_data);

			if ((PRO_CHM_D_X_D == value_data.v.i)||(PRO_CHM_45_X_D == value_data.v.i))
			{
				int nTempResult = FALSE;
				for (int i = 0; i <arrChamferAng.GetSize(); i++ )
				{
					if(DEQUAL(_wtof(arrChamferAng.GetAt(i)), 45.0))
					{
						return TRUE;
					}
				}
				if (nTempResult == FALSE)
				{
					return FALSE;
				}
			}
			else if (PRO_CHM_D1_X_D2 == value_data.v.i)
			{
				Leg1Val = GetChamferLeg1Val(pFeature,i);
				Leg2Val = GetChamferLeg2Val(pFeature,i);
				double dFeaAngle;
				dFeaAngle = atan(Leg1Val/Leg2Val);
				int nTempResult = FALSE;
				for (int i = 0; i <arrChamferAng.GetSize(); i++ )
				{
					if (DEQUAL(dFeaAngle/PI*180, _wtof(arrChamferAng.GetAt(i))) || DEQUAL(dFeaAngle/PI*180, 180 - _wtof(arrChamferAng.GetAt(i))))
					{
						nTempResult = TRUE;
					}
				}
				if (nTempResult == FALSE)
				{
					return FALSE;
				}
			}
			else if (PRO_CHM_ANG_X_D == value_data.v.i)
			{
				Leg2Val = GetChamferLeg2Val(pFeature,i);

				int nTempResult = FALSE;
				for (int i = 0; i <arrChamferAng.GetSize(); i++ )
				{
					if (DEQUAL(Leg2Val, _wtof(arrChamferAng.GetAt(i))) || DEQUAL(Leg2Val, 180 - _wtof(arrChamferAng.GetAt(i))))
					{
						nTempResult = TRUE;
					}
				}
				if (nTempResult == FALSE)
				{
					return FALSE;
				}
			}
		}
		else
		{
			break;
		}
		status = ProElempathFree(&pElemPath);
	}
	return TRUE;
}
Пример #6
0
void DatumRefResolver::HandleDatumPlane(ProSelection datum, vector<ProSelection> & result)
{
	ProAsmcomppath comppath;
	isis_ProSelectionAsmcomppathGet(datum, &comppath);

	ProModelitem mitem;
	isis_ProSelectionModelitemGet(datum, &mitem);

	ProFeature* feat;
	ProFeature f;

	if (mitem.type == PRO_FEATURE)
	{
		feat = &mitem;
	} else if (mitem.type == PRO_SURFACE || mitem.type == PRO_AXIS || mitem.type == PRO_EDGE || mitem.type == PRO_CSYS)
	{
		ProError err = isis_ProGeomitemFeatureGet ((ProGeomitem*)&mitem, &f);
		if (err != PRO_TK_NO_ERROR)
		{
			throw isis::application_exception("ProGeomitemFeatureGet error");
		}
		feat = &f;
	} else {
		throw isis::application_exception("DatumRefResolver::Resolve(): Unsupported datum type, only AXIS, PLANE and CSYS are supported. Datum type is:" + std::to_string((long long)mitem.type));
	}

	ProElement elemTree;
	isis_ProFeatureElemtreeExtract (feat, &comppath, PRO_FEAT_EXTRACT_NO_OPTS, &elemTree );

	ProElempathItem constraints_path_items[] = {
		{PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_DTMPLN_CONSTRAINTS},
	};

	/*wostringstream ostr;
	ostr << feat->id;
	ostr << L"elemtree.xml";
	ProPath filepath;
	wcscpy(filepath, ostr.str().c_str());
	isis_ProElemtreeWrite(elemTree, PRO_ELEMTREE_XML, filepath);*/

	ProElempath contraints_elem_path;
	isis_ProElempathAlloc(&contraints_elem_path);
	isis_ProElempathDataSet(contraints_elem_path, constraints_path_items, sizeof(constraints_path_items)/sizeof(ProElempathItem));

	int count;
	isis_ProElementArrayCount(elemTree, contraints_elem_path, &count);
	//isis::CreoMessageDialog(std::to_string((long long)count));

	// Get constraint array
	ProElement* constraintarray;
	isis_ProArrayAlloc(count,sizeof(ProElement),1,(ProArray*) &constraintarray);
	isis_ProElementArrayGet(elemTree, contraints_elem_path, &constraintarray);

	// Iterate through constraints
	for (int i = 0; i < count; i++)
	{
			ProElempathItem set_path_items[] = {
				{PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_DTMPLN_CONSTRAINTS},
				{PRO_ELEM_PATH_ITEM_TYPE_INDEX, i},
				{PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_DTMPLN_CONSTR_REF},
			};

			ProElement constraint;
			ProReference ref;
			int setid;
			ProElempath elem_path;
			ProElempathAlloc(&elem_path);
			isis_ProElempathDataSet(elem_path, set_path_items, sizeof(set_path_items)/sizeof(ProElempathItem));
			isis_ProElemtreeElementGet(elemTree, elem_path, &constraint);
			ProError err = ProElementReferenceGet(constraint, 0, &ref);
			if (err == PRO_TK_EMPTY)
			{
				AddIfMissing(datum, result);
				continue;
			} else if (err != PRO_TK_NO_ERROR)
			{
				throw isis::application_exception("ProElemtreeElementGet error :" + std::to_string((long long)err));
			}

			ProMdl refowner;
			err = ProReferenceOwnerGet(ref, &refowner);
			if (err != PRO_TK_NO_ERROR)
			{
				throw isis::application_exception("ProReferenceOwnerGet error");
			}
			/*ProName name;
			err = ProMdlNameGet(refowner, name);
			if (err != PRO_TK_NO_ERROR)
			{
				throw isis::application_exception("ProMdlNameGet error");
			}*/
			ProMdlType mdltype;
			err = ProMdlTypeGet(refowner, &mdltype);
			if (err != PRO_TK_NO_ERROR)
			{
				throw isis::application_exception("ProMdlTypeGet error");
			}
			ProSelection selection;
			ProReferenceToSelection(ref, &selection);
			if (mdltype==PRO_MDL_PART)
			{
				//isis::CreoMessageDialog(name);
				AddIfMissing(selection, result);
			} else {
				Resolve(selection, result);
				//throw isis::application_exception("Datum is not derived from a part");
			}
			//result.push_back(refowner);
			//ProSelection
	}
}