Brep相关接口

来源:互联网 发布:网络品牌男衬衫 编辑:程序博客网 时间:2024/05/29 14:50

//retrieves the feature associated to the BodyOUT

 CATISpecObject_var FeatureSolid = shapefeat->GetResultOUT();

 if ( NULL_var ==FeatureSolid )

 {

   cout <<"Error, the Feature Solid is NULL" <<endl;

   return 1;

 }

 

 

 //6 - 2 retrieving its associated geometry

 //

 

 CATIMfGeometryAccess_var geoAccess = FeatureSolid;

 if (NULL_var ==geoAccess)

 {

   cout <<"Error, the geometry access is NULL" <<endl;

   return 1;

 }

 

 //6 - 3 retrieving BRepAccess from geometry

 //

 CATLISTV(CATBaseUnknown_var)breps;

 int nbfaces =geoAccess -> GetBReps(breps);

 if (0 == nbfaces)

 {

   cout<<"Error, there is no face associated to the geometry"<<endl;

   return 1;

 }

 

 CATLISTP(CATIBRepAccess)ListBreps;

   CATIBRepAccess * Brep = NULL;

 CATBaseUnknown * Unk = NULL;

   

   for(intcompt = 1; compt <=nbfaces; compt++)

 {

      Unk = breps[compt];

   Brep = (CATIBRepAccess * )Unk;

   if (NULL !=Brep)

   {

     Brep->AddRef();

     ListBreps.Append(Brep);

   }

   }

 breps.RemoveAll();

 nbfaces = ListBreps.Size();

 if (0 == nbfaces)

 {

   cout<<"Error, there is no face in the BRepAccess List"<<endl;

   return 1;

 }

 else

 {

   cout<<"There is(are) "<<nbfaces<<" face(s) on the part"<<endl;

 }

 

 //

 //7 - retrieving and displaying current faces colors

 //

 cout<<"--------------------------"<<endl;

 cout<<"Retrieving current colors"<<endl;

 CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;

  

 rc = CATMmrApplicativeAttributes::GetColorsOnFaces(ListBreps, retrieveRed,retrieveGreen,retrieveBlue);

 if (E_FAIL ==rc )

 {

   cout<<"Error, an error occured while retrieving current part colors"<<endl;

   return 1;

 }

 

 for (compt =1;compt<=nbfaces;compt++)

 {

   cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;

}

 

2. o Access to hierarchy of features within part,

Part1//                    filtering on fillets

Part2//      o Access to topology associated to features

//                  o Graphical modification of this topology

Part1//

 // 6-1 Gets the fillet features

 //

 CATLISTV(CATISpecObject_var)filletFeatures;

 CATIDescendants *pPartAsDescendant =NULL;

 rc = spPart->QueryInterface(IID_CATIDescendants, (void**)&pPartAsDescendant) ;

 if( FAILED(rc) )

 {

     cout <<" The MechanicalPart does not implement CATIDescendant" <<endl;

     return 1;

 }

         

 pPartAsDescendant->GetAllChildren("CATIFillet",filletFeatures);

 

 for(intcurrentFillet=1; currentFillet<=filletFeatures.Size();currentFillet++)

 {

    const CATISpecObject_var&currentfilletFeature = filletFeatures[currentFillet];

    if ( NULL_var !=currentfilletFeature )

    {

       //

       // 6-2 Gets the BRep associated with the fillet

       //

       CATIMfGeometryAccess *pFilletAsGeomAccess =NULL;

       if (NULL_var !=currentfilletFeature)

          rc= currentfilletFeature->QueryInterface(IID_CATIMfGeometryAccess,

                                                     (void**)&pFilletAsGeomAccess) ;

       else

          rc = E_FAIL;

             

       if ( SUCCEEDED(rc) )

      {

          CATLISTV(CATBaseUnknown_var)filletBReps;

          pFilletAsGeomAccess->GetBReps(filletBReps);

 

          // 6-3 Colorizes BRep

          for(intcurrentBRep=1; currentBRep<=filletBReps.Size();currentBRep++)

         {

             CATIVisProperties *pFilletBrepAsGraphics = 0;

             const CATBaseUnknown_var&currentfilletBRep = filletBReps[currentBRep];

             if (NULL_var !=currentfilletBRep)

                rccurrentfilletBRep->QueryInterface(IID_CATIVisProperties,

                                                             (void**)&pFilletBrepAsGraphics) ;

             else

                rc = E_FAIL;

 

             if ( SUCCEEDED(rc) )

            {               

                CATVisPropertiesValues color;

                 color.SetColor(0, 255, 0);// green

                 pFilletBrepAsGraphics->SetPropertiesAtt(color,CATVPColor, CATVPMesh);

 

                 pFilletBrepAsGraphics->Release();

                 pFilletBrepAsGraphics = NULL ;

            }

         }

          pFilletAsGeomAccess->Release();

          pFilletAsGeomAccess = NULL ;

      }

    }

  }

  pPartAsDescendant->Release();

   pPartAsDescendant = NULL ;

 

Part2//

//

  // 7-5 Gets all two dimensional topo cells representing the Part body

  //

  CATLISTP(CATCell)cells;

  spPartTopoBody->GetAllCells(cells, 2);

 

 

  //

  // 7-6 Processes the two dimensional topo cells

  //

  for(intcurrentCell=1; currentCell<=cells.Size();currentCell++)

  {

     CATCell_var pCell ( cells[currentCell] );

     if ( NULL_var !=pCell )

     {

        CATGeometry *pGeometry =pCell->GetGeometry();

 

        if ( (NULL !=pGeometry) && (pGeometry->IsATypeOf(CATPlaneType)) )

        {

           CATIBRepAccess_var spBRepAccess ( CATBRepDecode(pCell,spFeatureResultGeomElem) );

           if( NULL_var!=spBRepAccess )

           {

              //

              // 7-7 Colorizes BRep

              //

              CATIVisProperties *pBRepAccessAsGraphics = 0;

              rc= spBRepAccess->QueryInterface(IID_CATIVisProperties,

                                            (void**)&pBRepAccessAsGraphics) ;

              if ( SUCCEEDED(rc) )

              {

                 CATVisPropertiesValues color;

                 color.SetColor(0, 0, 255);// Blue

                 pBRepAccessAsGraphics->SetPropertiesAtt(color,CATVPColor, CATVPMesh);

                 

                 pBRepAccessAsGraphics->Release();

                 pBRepAccessAsGraphics = NULL ;

              }

           }

        }

     }

   }

1.       通过BRep feature询问CATIMfBRep接口

 

HRESULTColorBrushDlg::SetColorOnFaceBreps(CATListValCATISpecObject_varTargetFace)

{

   //// -------------------------------------------------

   for(intobjId = 1; objId <=TargetFace.Size();objId++)

   {

 

      CATIMfBRep* pFaceAsBrep = NULL;

      TargetFace[objId]->QueryInterface(IID_CATIMfBRep,(void**)&pFaceAsBrep);

      if ( NULL !=pFaceAsBrep )

      {

          //

          // 6-2 Gets the BRep associated with the Face

          //

          HRESULT rc= S_OK;

          

          //此方法可以成功更改颜色属性!但需更新后方能显示

          CATLISTV(CATBaseUnknown_var)selectFaceBreps;

          selectFaceBreps = pFaceAsBrep->GetBRep( TargetFace[objId]);//Returns the selecting objects associated with the BRep feature

          for(intcurrentBRep=1; currentBRep<=selectFaceBreps.Size();currentBRep++)

          {

             CATIVisProperties *pFilletBrepAsGraphics = 0;

             const CATBaseUnknown_var&currentselectFaceBRep = selectFaceBreps[currentBRep];

             if (NULL_var !=currentselectFaceBRep)

                 rccurrentselectFaceBRep->QueryInterface(IID_CATIVisProperties,

                 (void**)&pFilletBrepAsGraphics) ;

             else

                 rc = E_FAIL;

 

             if ( SUCCEEDED(rc) )

             {               

                 CATVisPropertiesValues color;

                 color.SetColor(ired,igreen, iblue);// set color

                 pFilletBrepAsGraphics->SetPropertiesAtt(color,CATVPColor, CATVPMesh);

 

                 pFilletBrepAsGraphics->Release();

                 pFilletBrepAsGraphics = NULL ;

                 ////--------------------更新--------没效果------QI失败-------

                 //CATIModelEvents *piME = NULL;

                 //rc = currentselectFaceBRep->QueryInterface( IID_CATIModelEvents,(void **) &piME);

                 //if( FAILED(rc) || piME == NULL ) return rc;

                 //CATModifyVisProperties notif(currentselectFaceBRep, CATPathElement(currentselectFaceBRep), CATVPGlobalType,CATVPColor,color);

                 //piME->Dispatch(notif);

                 //piME->Release();

                 //piME= NULL ;

             }

          }

 

          ////--------------------更新--------没效果-------------

          //HRESULT hr = ::CAAGsiObjectUpdate(TargetFace[objId]);

          //if(FAILED(hr))

          //{

          //  ::Send_message("Failed to update current select face!");

          //  return E_FAIL;

          //}

 

      }

 

   }  

   //-----------------------------------------

   return S_OK;

}

//刷新Update ,更新视图

for(int bodyId = 1; bodyId <= listTargetBody.Size(); bodyId++)
  {
   CATVisPropertiesValues color;
   color.SetColor(ired, igreen, iblue);
   CATIModelEvents *piME = NULL;
   HRESULT rc = listTargetBody[bodyId]->QueryInterface( IID_CATIModelEvents,(void **) &piME);
   if( FAILED(rc) || piME == NULL ) continue;
   CATModifyVisProperties notif(listTargetBody[bodyId], CATPathElement(listTargetBody[bodyId]), CATVPGlobalType,CATVPColor,color);
   piME->Dispatch(notif);
   piME->Release();
   piME= NULL ;   
   
  }

原创粉丝点击