测试前模型与结构树示意图
测试后模型型示意图
if (pEditor!=NULL)
{
CATDocument*pDoc=pEditor->GetDocument();
if (pDoc!=NULL)
{
CATInit*piInt=NULL;
HRESULT hr=pDoc->QueryInterface(IID_CATInit,(void**)&piInt);
if (SUCCEEDED(hr)&&piInt!=NULL)
{
CATIPrtContainer*piPrtCon=(CATIPrtContainer*)piInt->GetRootContainer("CATIPrtContainer");
if (piPrtCon!=NULL)
{
piInt->Release();
CATIPrtPart_var spiPart=piPrtCon->GetPart();
CATIDescendants*piDes=NULL;
hr=spiPart->QueryInterface(IID_CATIDescendants,(void**)&piDes);
CATLISTV(CATISpecObject_var)oListFeature;
if (piDes!=NULL&&SUCCEEDED(hr))
{
piDes->GetAllChildren("CATIPad",oListFeature);
piDes->Release();
CATISpecObject*piSpecOb=oListFeature[1]->GetRootFather();
for (int i=1;i<=oListFeature.Size();i++)
{
CATIMfGeometryAccess*piMfGeoAcc=NULL;
hr=oListFeature[i]->QueryInterface(IID_CATIMfGeometryAccess,(void**)&piMfGeoAcc);
CATIGeometricalElement_var spiGeoEle=NULL_var;
HRESULT rc=oListFeature[i]->QueryInterface(IID_CATIGeometricalElement,(void**)&spiGeoEle);
if (SUCCEEDED(hr)&&piMfGeoAcc!=NULL&&SUCCEEDED(rc)&&spiGeoEle!=NULL)
{
CATLISTV(CATBaseUnknown_var)oListUnknown;
piMfGeoAcc->GetBReps(MfKeyTop,spiGeoEle,oListUnknown);
piMfGeoAcc->Release();
if (oListUnknown.Size())
{
for (int j=1;j<=oListUnknown.Size();j++)
{
CATIVisProperties *pBRepAccessAsGraphics = 0;
hr =oListUnknown[j]->QueryInterface(IID_CATIVisProperties,
(void**)&pBRepAccessAsGraphics);
cout<<"8"<<endl;
if( SUCCEEDED(hr))
{
cout<<"9"<<endl;
CATVisPropertiesValues color;
color.SetColor(0, 0, 255); // Blue
pBRepAccessAsGraphics->SetPropertiesAtt(color,CATVPColor,CATVPMesh);
pBRepAccessAsGraphics->Release();
pBRepAccessAsGraphics = NULL ;
}
}
}
}
}
//强制刷新模型 CATModify 对象任意类型的可视化事件
CATModify pModify(piSpecOb);
CATIModelEvents_var spiModelEvent=piSpecOb;
spiModelEvent->Dispatch(pModify);
}
}
}
}
}
else{
cout<<"Editor null"<<endl;
}
关键接口:CATIMfGeometryAccess 该接口可通过通用名和符号信息获取选择对象和拓扑单元