CATIA二次开发源码分享: 获取所有的圆角类型并着色
CATIA二次开发源码分享: 获取所有的圆角类型并着色
本部分主要学习如何对特征进行颜色标记处理!
重要的是思路,通过CATIPrtPart 获取CATIDecendants接口,在这里可以设置要查询的类型,通过获取的特征得到特征对应几何的Brep信息,从而可以调用可视化的方法进行颜色处理!对于CATVPMesh的类型主要可以处理颜色和透明度。
{
// Begin of User Code
CATFrmEditor *pEditor = CATFrmEditor::GetCurrentEditor();
if (NULL == pEditor)
{
printMessage("No Editor");
return;
}
CATDocument *pDoc = pEditor->GetDocument();
if (NULL == pDoc)
{
printMessage("No Doc");
return;
}
//CatInit
CATInit *pDocAsInit = NULL;
HRESULT rc;
rc = pDoc->QueryInterface(IID_CATInit,(void **) &pDocAsInit);
if (FAILED(rc))
{
printMessage("Can't get the document data");
return;
}
//get the root container
CATIPrtContainer * pPrtContainer = NULL;
pPrtContainer = (CATIPrtContainer *)pDocAsInit->GetRootContainer("CATIPrtContainer");
if (NULL == pPrtContainer)
{
printMessage("Can't get the mechanical Feature");
return;
}
pDocAsInit->Release();
pDocAsInit= NULL;
// get mechnical part
CATIPrtPart_var spPrtPart = NULL_var;
spPrtPart = pPrtContainer->GetPart();
if (NULL_var == spPrtPart)
{
printMessage("Can't get the mechanical Part");
return;
}
pPrtContainer->Release();
pPrtContainer = NULL;
//get the CATIDecendants
CATIDescendants *pDescendants = NULL;
rc = spPrtPart->QueryInterface(IID_CATIDescendants,(void **) &pDescendants);
if (FAILED(rc))
{
printMessage("Can't get the CATIDescendants");
return;
}
CATLISTV(CATISpecObject_var) spFilletFeatures;
pDescendants->GetAllChildren("CATIFillet",spFilletFeatures);
for (int currentFillet = 1; currentFillet <= spFilletFeatures.Size();currentFillet++)
{
CATISpecObject_var spCurrentFilletFeature = spFilletFeatures;
if (NULL_var != spCurrentFilletFeature)
{
//get the name alias and print
CATIAlias_var spAlias = spCurrentFilletFeature;
if (NULL_var == spAlias)
{
continue;
}
CATUnicodeString filletName = spAlias->GetAlias();
//printMessage();
_SelectorList1->SetLine(filletName);
//get the Brep of the fillet
CATIMfGeometryAccess *pMfGeoAccess = NULL;
rc = spCurrentFilletFeature->QueryInterface(IID_CATIMfGeometryAccess,(void **) &pMfGeoAccess);
if (SUCCEEDED(rc))
{
CATLISTV(CATBaseUnknown_var) spOBreps;
pMfGeoAccess->GetBReps(spOBreps);
for (int i = 1; i <= spOBreps.Size();i++)
{
CATIVisProperties *pfilletBrepAsGraphics = NULL;
CATBaseUnknown_var spCurrentFillet = spOBreps;
if (NULL_var != spCurrentFillet)
{
rc = spCurrentFillet->QueryInterface(IID_CATIVisProperties,(void **) &pfilletBrepAsGraphics);
if (SUCCEEDED(rc))
{
CATVisPropertiesValues colorValues;
colorValues.SetColor(0,255,0);//green
colorValues.SetOpacity(50);
pfilletBrepAsGraphics->SetPropertiesAtt(colorValues,CATVPColor,CATVPMesh);
pfilletBrepAsGraphics->SetPropertiesAtt(colorValues,CATVPOpacity,CATVPMesh);
pfilletBrepAsGraphics->Release();
pfilletBrepAsGraphics = NULL;
}
}
}
pMfGeoAccess->Release();
pMfGeoAccess = NULL;
}
}
}
pDescendants->Release();
pDescendants = NULL;
// End of User Code
}
颜色属性类别如下:本文用到了颜色和透明度
enum CATVisPropertyType {CATVPColor,
CATVPOpacity,
CATVPSymbol,
CATVPLineType,
CATVPWidth,
CATVPInheritance,
CATVPLayer,
CATVPShow,
CATVPPick,
CATVPLowInt,
CATVPRenderingStyle,
CATVPAllPropertyType
}
几何类型对应的颜色类型如下: 本文使用的是CATVPMesh
CATVPGlobalType
This type defines the group of property types:
CATVPPick
CATVPShow
CATVPLayer
CATVPMesh
The geometry is surfacic.
This geometry uses these property types:
CATVPColor
CATVPOpacity
CATVPEdge
The geometry is an edge.
This geometry uses these property types:
CATVPColor
CATVPWidth
CATVPLineType
CATVPLine
The geometry is a line.
This geometry uses these property types:
CATVPColor
CATVPWidth
CATVPLineType
CATVPPoint
The geometry is a point.
This geometry uses these property types:
CATVPColor
CATVPSymbol
CATVPAsm
The geometry is a set of geometry. This type allows you to have inheritance.
This geometry uses these property types:
CATVPColor
CATVPInheritance
CATVPWidth
CATVPLineType
CATVPOpacity
页:
[1]