CATIA二次开发——将样条转换为NUPBS(非均匀多项式样条)

	CATFrmEditor*pEdiotr=_pPathAgent->GetEditor();
	CATDocument*pDoc=NULL;
	if (pEdiotr!=NULL)
	{
		pDoc=pEdiotr->GetDocument();
	}
	CATIContainerOfDocument*pConOfDoc=NULL;
	HRESULT rc=pDoc->QueryInterface(IID_CATIContainerOfDocument,(void**)&pConOfDoc);
	CATIPrtContainer*pPrtCon=NULL;
	if (SUCCEEDED(rc)&&pConOfDoc!=NULL)
	{
		CATIContainer*opCon=NULL;
		pConOfDoc->GetSpecContainer(opCon);
		pPrtCon=(CATIPrtContainer*)opCon;
		if (pPrtCon==NULL)
		{
			cout<<"Get Container error"<<endl;
			return TRUE;
		}
	}
	cout<<"step 1"<<endl;
	CATPathElement*pPath=_pPathAgent->GetValue();
	if (pPath!=NULL)
	{
		int EleIndex=pPath->GetSize()-1;
		CATBaseUnknown*pElement=(*pPath)[EleIndex];
		CATIGeometricalElement*pGeoElement=NULL;
		if (pElement!=NULL)
		{
			if (SUCCEEDED(pElement->QueryInterface(IID_CATIGeometricalElement,(void**)&pGeoElement)))
			{
				cout<<"step 2"<<endl;
				CATBody_var spBody=pGeoElement->GetBodyResult();
				CATBody*pBody=spBody;
				if (pBody!=NULL)
				{
					CATLISTP(CATCell)ListCell;
					spBody->GetAllCells(ListCell,1);
					CATCell*pCell=ListCell[1];
					CATEdge*pEdge=(CATEdge*)pCell;
					 CATGeometry *pGeo=pCell->GetGeometry();
					 if (pGeo==NULL)
					 {
						 cout<<"geo null"<<endl;
						 return TRUE;
					 }

					CATGeoFactory*pGeoFac=pGeo-> GetContainer();
					if (pGeo==NULL)
					{
						cout<<"contianer null"<<endl;
						return TRUE;
					}
					CATSoftwareConfiguration*pSoftWare=new CATSoftwareConfiguration();
					CATTopData TopData(pSoftWare);
					CATTopCrvToNurbsCrvOperator*pTopCrvToNubrs=::CATCreateTopCrvToNurbsCrvOperator(pGeoFac,&TopData,pBody,pEdge);
					cout<<"step 3"<<endl;
					if (pTopCrvToNubrs!=NULL)
					{
						pTopCrvToNubrs->SetRationalAbility(0);//运行Run()方法前需要,设定适当的参数,否则无法获取运算结果
						pTopCrvToNubrs->Set3DOutputDimension(TRUE);
						CATLONG32 ioMaxDegree=3;
						pTopCrvToNubrs->SetMaxDegree(ioMaxDegree);
						pTopCrvToNubrs->Run();
						CATLONG32 oIsExact;
						pTopCrvToNubrs->IsExactTransformation(oIsExact);
						cout<<oIsExact<<endl;
						CATBody*pNewBody=pTopCrvToNubrs->GetResult();
						if (pNewBody!=NULL)
						{

							cout<<"step 4"<<endl;
							CATLISTP(CATCell)NewListCell;
							pNewBody->GetAllCells(NewListCell,1);
							CATCell*pCell=NewListCell[1];
							CATEdge*pEdge=(CATEdge*)pCell;
							CATEdgeCurve*pEdgeCurve=pEdge->GetCurve();
							CATNurbsCurve*pNubrsCurve=(CATNurbsCurve*)pEdgeCurve->GetRefCurve();
							double ioCofficient,ioShift;
							pNubrsCurve->GetOriginalParametrisationDATA(ioCofficient,ioShift);
							cout<<ioCofficient<<" "<<ioShift<<endl;
							const CATKnotVector*pVector=pNubrsCurve->GetKnotVector();
							if (pVector!=NULL)
							{
								
									short KontNum=pVector->GetNumberOfKnots();
									const double*oknotvector=NULL;
									pVector->GetKnots(oknotvector);
									for (int i=0;i<KontNum;i++)
									{
										cout<<(*(oknotvector+i)-ioShift)/ioCofficient<<endl;
									}
									
							}
							CATBoolean tag=pNubrsCurve->IsRational();
							if (tag==FALSE)
							{
								cout<<"Not Retional"<<endl;
								_pDlgNubrs->CovToValue("Not Retional");
							}else{
								_pDlgNubrs->CovToValue("Is Retional");
							}
						
						}
						//获取原始Spline曲线别名
							CATUnicodeString Alias;
							CATIAlias*pAlias=NULL;
							if (SUCCEEDED(pElement->QueryInterface(IID_CATIAlias,(void**)&pAlias)))
							{
								Alias=pAlias->GetAlias();
								pAlias->Release();
								pAlias=NULL;
							}
						//删除原有特征
						LifeCycleObject*pLifeCycleObject=NULL;
						if (SUCCEEDED(pElement->QueryInterface(IID_LifeCycleObject,(void**)&pLifeCycleObject)))
						{
							pLifeCycleObject->remove();
							pLifeCycleObject->Release();
							pLifeCycleObject=NULL;
						}
						//显示转换后的NUPBS样条
						CATIDatumFactory_var spDatumFac=pPrtCon;
						if (spDatumFac!=NULL_var)
						{
							CATISpecObject*opSpecObject=NULL;
							spDatumFac->InstanciateDatum(pNewBody,opSpecObject);
							if (opSpecObject==NULL)
							{
								return TRUE;

							}
							CATTry{
							opSpecObject->Update();
							//设置转换后样条别名
							CATIAlias *piNewAlias=NULL;
							if (SUCCEEDED(opSpecObject->QueryInterface(IID_CATIAlias,(void**)&piNewAlias)))
							{
								piNewAlias->SetAlias(Alias);
								piNewAlias->Release();
								piNewAlias=NULL;
							}
							CATIGSMProceduralView_var spView=opSpecObject;
							spView->InsertInProceduralView();
							}CATCatch(CATError,pError){
								if (pError!=NULL)
								{
									cout<<pError->GetNLSMessage().ConvertToChar()<<endl;
								}
							}CATEndTry;
						}
				
						
					}
	
					delete pTopCrvToNubrs;
					pTopCrvToNubrs=NULL;
					/*				delete pGeoFac;
					pGeoFac=NULL;*/
					//关闭GeoFactor
					/*::CATCloseCGMContainer(pGeoFac);  */
					//次几何工厂由当前文档内几何元素获取,不用手动使用全局函数关闭或delete掉,否则文档内所有元素将被删除
				}
			
			}
		}
		pGeoElement->Release();
		pGeoElement=NULL;
	}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值