在零件根目录下创建GeoSet,创建前先判断是否已经存在


HRESULT pklkpppp::CreateNewGeoSet(CATIProduct_var ispiProd,CATUnicodeString istrName,CATBoolean& oIsNewGeo,CATISpecObject_var &ospiSpecGeoSet)
{
HRESULT rc = S_OK;
if (ispiProd == NULL_var)
{
return E_FAIL;
}
oIsNewGeo = TRUE;
CATIProduct_var ispiProdRef = ispiProd->GetReferenceProduct();
if (ispiProdRef==NULL_var)
{
return E_FAIL;
}
CATILinkableObject *piLinkableObjOnChild = NULL;
rc = ispiProdRef->QueryInterface(IID_CATILinkableObject,(void**)&piLinkableObjOnChild);
if (FAILED(rc))
{
return E_FAIL;
}
CATDocument *pDocOnChild = NULL;
pDocOnChild = piLinkableObjOnChild->GetDocument();
if (NULL == pDocOnChild)
{
return E_FAIL;
}
CATIContainerOfDocument_var spContOfDocOnChild = pDocOnChild;
CATIContainer *piSpecContainerOnChild = NULL;
rc = spContOfDocOnChild->GetSpecContainer(piSpecContainerOnChild);
if (FAILED(rc))
{
return E_FAIL;
}
CATIPrtContainer *piPrtContainerOnChild = NULL;
rc = piSpecContainerOnChild->QueryInterface(IID_CATIPrtContainer,(void**)&piPrtContainerOnChild);
piSpecContainerOnChild->Release();
if (FAILED(rc))
{
return E_FAIL;
}
CATIPrtPart_var spPartOnChild = piPrtContainerOnChild->GetPart();
piPrtContainerOnChild->Release();
if (NULL_var == spPartOnChild)
{
return E_FAIL;
}
//先判断有没有RPS几何图形集
CATIPartRequest *pPartAsRequest = NULL;
rc = spPartOnChild->QueryInterface(IID_CATIPartRequest, (void**)&pPartAsRequest);
if (FAILED(rc))
{
return E_FAIL;
}
//遍历所有GS
CATLISTV(CATBaseUnknown_var) lstGeomSet = NULL;
pPartAsRequest->GetSurfBodies("", lstGeomSet);
//如果没有GS或者没有给名字,则直接建立
CATISpecObject_var spChildTool = NULL_var;
if (lstGeomSet == NULL || istrName == "")
{
//获得几何图形集创建的父级,该处为最外层根下
CATISpecObject_var spParentTool = spPartOnChild;
//
CATIMechanicalRootFactory_var spMechRootFactory = piSpecContainerOnChild;
//
//CATISpecObject_var spChildTool = NULL_var;
rc = spMechRootFactory->CreateGeometricalSet(istrName,spParentTool,spChildTool,-1);
if (FAILED(rc))
{
return E_FAIL;
}
//定义到新建的几何图形集下
spPartOnChild->SetCurrentFeature(spChildTool);
}
//有GS,则遍历GS,并判断是否已经含有该名字的几何图形集
else
{
CATBoolean boolExistGS = FALSE;
for (int i=1; i <= lstGeomSet.Size(); i++)
{
CATBaseUnknown_var spCurrentSet = lstGeomSet[i];
if (spCurrentSet == NULL_var)
{
continue;
}
CATIAlias_var spAliasOnCurrentSet = spCurrentSet;
CATUnicodeString strAliasOnCurrentSet = spAliasOnCurrentSet->GetAlias();
//如果存在,则直接定义到该图形集
if (strAliasOnCurrentSet == istrName)
{
oIsNewGeo = FALSE;
spChildTool = spCurrentSet;
spPartOnChild->SetCurrentFeature(spChildTool);
boolExistGS = TRUE;
break;
}
}
//不存在,则新建图形集
if (boolExistGS == FALSE)
{
//获得几何图形集创建的父级,该处为最外层根下
CATISpecObject_var spParentTool = spPartOnChild;
//
CATIMechanicalRootFactory_var spMechRootFactory = piSpecContainerOnChild;
//
//CATISpecObject_var spChildTool = NULL_var;
rc = spMechRootFactory->CreateGeometricalSet(istrName,spParentTool,spChildTool,-1);
if (FAILED(rc))
{
return E_FAIL;
}
//定义到新建的几何图形集下
spPartOnChild->SetCurrentFeature(spChildTool);
}
}
ospiSpecGeoSet = spChildTool;
return rc;
}

posted @ 2021-08-05 16:40  Breadss  阅读(157)  评论(0编辑  收藏  举报