加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

caa开发学习5_几何体、有序几何图形集、几何图形集、零件几何体

(2016-09-27 15:17:41)
分类: catia开发(caa)
void GetObjectsInPart()
{
//1.获得Editor   【pEditor】
    HRESULT rc;
    CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();

    //2.获得Document 【pDoc】
CATDocument *pDoc = pEditor->GetDocument();   
if (  NULL ==pDoc  )
{
return ;
}
//3.从doc中获取prt文件的初始化 【pDocAsInit】
CATInit *pDocAsInit = NULL ;
rc = pDoc->QueryInterface(IID_CATInit, (void**)&pDocAsInit);
if ( FAILED(rc) )
{
return   ;
}


    //4.获取prtContainer  【pSpecContainer】
CATIPrtContainer *pSpecContainer = NULL ;
pSpecContainer = (CATIPrtContainer*)pDocAsInit->GetRootContainer("CATIPrtContainer");
if ( NULL == pSpecContainer )
{
return  ;
}
pDocAsInit->Release();//内存释放
pDocAsInit = NULL ;



// 5.获取Part特征  【spPart】
CATIPrtPart_var spPart = pSpecContainer->GetPart();//
if ( NULL_var == spPart )
{
return ;
}
pSpecContainer->Release();
pSpecContainer = NULL ;

// 6.【IID_CATIDescendants】
CATIDescendants *pPartAsDescendants = 0;
rc = spPart->QueryInterface(IID_CATIDescendants, (void**)&pPartAsDescendants) ;
if ( FAILED(rc) )
{
return  ;
}
 
// 6.1【CATIMechanicalTool】几何体和零件几何体
CATLISTV(CATISpecObject_var) BodyListDesc;  
pPartAsDescendants->GetAllChildren("CATIMechanicalTool", BodyListDesc);//
// ShowObjects2(BodyListDesc);

// 6.2 有序几何图形集【CATIMmiOrderedGeometricalSet】
CATLISTV(CATISpecObject_var) OGSList;  
pPartAsDescendants->GetAllChildren("CATIMmiOrderedGeometricalSet",OGSList);//
// ShowObjects2(OGSList);
 

// 6.3 几何图形集【CATIMmiNonOrderedGeometricalSet】
CATLISTV(CATISpecObject_var) GSList;
pPartAsDescendants->GetAllChildren("CATIMmiNonOrderedGeometricalSet",GSList);//
//ShowObjects2(GSList);


pPartAsDescendants->Release();
pPartAsDescendants = NULL ;


// 7.【IID_CATIPartRequest】
CATIPartRequest *pPartAsRequest = 0;
rc = spPart->QueryInterface(IID_CATIPartRequest, (void**)&pPartAsRequest) ;
if ( FAILED(rc) )
{
return   ;
}


const CATUnicodeString stdContext(" "); // Sets the context for topo bodies lookup 
// 7.1 【BodyList】几何体和零件几何体
CATLISTV(CATBaseUnknown_var) BodyList;  
pPartAsRequest->GetSolidBodies(stdContext, BodyList);
ShowObjects(BodyList);
// 7.2 【SurfacicSetList】几何图形集
CATLISTV(CATBaseUnknown_var) SurfacicSetList;  
pPartAsRequest->GetSurfBodies(stdContext, SurfacicSetList);
//  ShowObjects(SurfacicSetList);

pPartAsRequest->Release();
pPartAsRequest = NULL ;

}



void ShowObjects(const CATLISTV(CATBaseUnknown_var) &iSet)
{
  const CATUnicodeString stdContext(""); 

  for(int curSetIdx=1; curSetIdx<=iSet.Size(); curSetIdx++)
  {
 //1.取出第curSetIdx个集合 【CurrentSet】
      CATBaseUnknown_var CurrentSet = iSet[curSetIdx] ;
      if ( NULL_var == CurrentSet ) break ;

      CATIAlias_var aliasOnCurrentSet = CurrentSet ;
      if ( NULL_var != aliasOnCurrentSet)
      {
//AddinMultiList(aliasOnCurrentSet->GetAlias());
 CATUnicodeString istring = aliasOnCurrentSet->GetAlias();
                    
wchar_t charTmp[100] = {0};
istring.ConvertToWChar(charTmp);
 MessageBox(NULL,charTmp,TEXT("集合"),MB_OK);
      }


      CATLISTV(CATBaseUnknown_var) pListResult;
      CATIBodyRequest *pBodyRequestOnCurrentSet = NULL;
 //2.取出【CurrentSet】里面的元素放在【pListResult】
      HRESULT rc = CurrentSet->QueryInterface(IID_CATIBodyRequest, (void**)&pBodyRequestOnCurrentSet);
      if ( SUCCEEDED(rc) )
      {   
    
         rc = pBodyRequestOnCurrentSet->GetResults(stdContext, pListResult);
         if ( SUCCEEDED(rc) )
         {
            int SizeListResult = pListResult.Size() ;
 
//3.取出第curSetIdx个元素 【CurrentFeat】
            for(int curFeatIdx=1; curFeatIdx<=SizeListResult; curFeatIdx++)
            {
               CATBaseUnknown_var CurrentFeat = pListResult[curFeatIdx] ;
               if ( NULL_var == CurrentFeat ) break ;

                CATIAlias_var aliasOnCurFeat =  CurrentFeat ;
                if ( NULL_var != aliasOnCurFeat)
                {
//AddinMultiList(aliasOnCurFeat->GetAlias());
CATUnicodeString istring = aliasOnCurFeat->GetAlias();
                   
wchar_t charTmp[100] = {0};
istring.ConvertToWChar(charTmp);
MessageBox(NULL,charTmp,TEXT("元素"),MB_OK);
                }


                CATIGeometricalElement *pGeomEltOnCurFeat = 0;
                rc = CurrentFeat->QueryInterface(IID_CATIGeometricalElement, 
                                                               (void**)&pGeomEltOnCurFeat);
                if( SUCCEEDED(rc) )
                {       
                   CATBody_var ResultBody = pGeomEltOnCurFeat->GetBodyResult();
        
                   if( NULL_var != ResultBody )
                   {
                      CATICGMObject *pCurTopo = NULL ;
                      rc=ResultBody->QueryInterface(IID_CATICGMObject,(void**)&pCurTopo);
                      if( SUCCEEDED(rc) )
                      {            
                         CATULONG32 curResultTag = pCurTopo->GetPersistentTag();
                     

                         pCurTopo->Release();
            pCurTopo = NULL ;
                      }else ;
                   }else ;

                   pGeomEltOnCurFeat->Release();
                   pGeomEltOnCurFeat = NULL ;
                }
            }
}else;

         pBodyRequestOnCurrentSet->Release();
         pBodyRequestOnCurrentSet = NULL ;
      }
      else 
      {
       ;
      }
 


}









void ShowObjects2(const CATLISTV(CATISpecObject_var) &iSetSpecObj) 
{
   CATLISTV(CATBaseUnknown_var) iSetBU ;
   for (int i=1; i<=iSetSpecObj.Size(); i++)
   {
      iSetBU.Append(iSetSpecObj[i]);
   }
   ShowObjects(iSetBU);
}




0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有