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;
}
CATIA二次开发——将样条转换为NUPBS(非均匀多项式样条)
最新推荐文章于 2021-11-27 10:44:54 发布