日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

#开发catia_CATIA工程制图二次开发之15:从平面创建剖面视图

發布時間:2025/3/21 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 #开发catia_CATIA工程制图二次开发之15:从平面创建剖面视图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

從平面創建剖面視圖

如何創建與平面關聯的切割剖面視圖

摘要

本文討論 CAADrwCreateSectionFromPlane用例。此用例說明如何創建由與平面關聯的切割剖面定義的生成剖面視圖。因此,如果移動平面,則節視圖將在更新后修改。

  • 您將使用此用例學習什么
  • CAADrwCreateSectionFromPlane 用例
    • CAADrwCreateSectionFromPlane能做什么
    • 如何啟動CAADrwCreateSectionFromPlane
    • 在哪找到CAADrwCreateViewFrom3D代碼
  • 步驟
  • 總之
  • 參考

您將使用此用例學習什么

此用例旨在向您展示如何從 3D 平面創建繪圖生成剖面視圖。

圖 1:包含平面" PlaneForSection "的零件文檔

PlaneForSection平面(查看器中的黃色平面)允許您從 3D 文檔管理繪圖剖面視圖的切割輪廓。

CAADrwCreateSectionFromPlane 用例

CAADrwCreateSectionFromPlane是http://CAADraftingInterfaces.edu框架的一個用例,它說明了DraftingInterfaces框架功能。

CAADrwCreateSectionFromPlane 能做什么

圖 2:使用新剖面視圖繪制文檔

如何啟動CAADrwCreateSectionFromPlane

要啟動 CAADrwCreateSectionFromPlane,您需要設置構建時間環境,然后編譯 CAADrwCreateSectionFromPlane及其先決條件,設置運行時環境,然后執行用例 [1]。

啟動用例時,將繪圖文件的完整路徑名作為參數傳遞。零件文件以以下路徑傳遞:http://CAADraftingInterfaces.eduCNextresourcesgraphicPartWithPlaneAndSketchForSectionView.CATPart.

  • 在Windows中

e:> mkrun -c cmd

CAADrwCreateSectionFromPlane c:...PartWithPlaneAndSketchForSectionView.CATPart c:DrawingTestOutput.CATDrawing

  • 在UNIX中

$ mkrun -c cmd

CAADrwCreateSectionFromPlane /u/users/.../PartWithPlaneAndSketchForSectionView.CATPart /u/users/DrawingTestOutput.CATDrawing

在哪找到CAADrwCreateSectionFromPlane代碼

CAADrwCreateSectionFromPlane 用例由一個名為 CAADrwCreateSectionFromPlane.cpp 的單一源文件組成。http://CAADraftingInterfaces.edu框架的CAADrwCreateSectionFromPlane.m模塊:

Windows

InstallRootDirectoryhttp://CAADraftingInterfaces.eduCAADrwCreateSectionFromPlane.m

Unix

InstallRootDirectory/http://CAADraftingInterfaces.edu/CAADrwCreateSectionFromPlane.m/

其中InstallRootDirectory 是安裝 CAA CD-ROM 的目錄。

步驟

CAADrwCreatViewFrom3D中有五個步驟:

1. 創建和初始化文檔

2. 在文檔中創建繪圖

3. 檢索零件文檔和黃色平面"PlaneForSection"

4. 從平面" PlaneForSection "創建剖面視圖

5. 保存文檔和退出

創建和初始化文檔

int main(int iArgc, // 參數數(2)

char** iArgv) // 新建*.CATDrawing文檔的路徑

{

// 檢查參數

if(3 != iArgc) return 1;

const char *pfileNamePart = iArgv[1];

const char *pfileNameOut = iArgv[2];

int code_err = 1;

// 創建會話

// ==================

CATSession *pSampleSession = NULL;

HRESULT hr = ::Create_Session("SampleSession",pSampleSession);

if (FAILED(hr)) return 1;

...

本節表示加載 CATIA 文檔 [2] 的常用順序。

在文檔中創建繪圖

...

// 繪制文檔創建

// ===============================

CATDocument* pNewDoc = NULL;

CATDocumentServices::New("CATDrawing", pNewDoc);

...

完全初始化繪圖文檔的其他步驟包含在特定的子程序中,CreateViewFrom3DInDrawingDoc。

[Top]

檢索零件文檔和平面" PlaneForSection "

...

// 讀取零件文檔并獲得相應的草圖

// =============================================================

CATDocument *pDocPart = NULL;

if( SUCCEEDED(CATDocumentServices::OpenDocument(pfileNamePart, pDocPart)) && pDocPart)

{

CATInit_var spInitOnDoc(pDocPart);

if(NULL_var != spInitOnDoc)

{

// 檢索根容器

CATIPrtContainer * piPrtCont = (CATIPrtContainer*) spInitOnDoc->GetRootContainer("CATIPrtContainer");

if (piPrtCont)

{

// 獲取容器的零件功能。

CATIPrtPart_var spPart = piPrtCont->GetPart();

// Get the appropriate plane

CATIDescendants *piDescPart=NULL;

if (SUCCEEDED(spPart->QueryInterface(IID_CATIDescendants,(void**)&piDescPart)))

{

CATListValCATISpecObject_var listFeatures;

piDescPart->GetAllChildren ("CATPlane",listFeatures) ;

int nbChilds = listFeatures.Size();

CATISpecObject_var spFeat;

for (int i = 1; i <= nbChilds; i++)

{

spFeat = listFeatures[i];

if (NULL_var != spFeat)

{

CATPlane* piPlane = NULL;

if (SUCCEEDED(spFeat->QueryInterface(IID_CATPlane, (void**)&piPlane)))

{

CATIAlias *piPlaneAlias = NULL;

if (SUCCEEDED(piPlane->QueryInterface(IID_CATIAlias, (void**)&piPlaneAlias)))

{

CATUnicodeString PlaneName = piPlaneAlias->GetAlias();

const CATUnicodeString PlaneSection_UC = "PlaneForSection";

if (PlaneName == PlaneSection_UC)

hr = CreateSectionViewFromPlanInDrawingDoc(pNewDoc, piPlane);

...

使用 CATIDescendants接口的 GetAllChildren方法檢索零件文檔中的所有平面。由于 CATIAlias 接口的 GetAlias 方法,從列表中提取適當的平面。

從平面" PlaneForSection "創建剖面視圖

...

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

// 從平面創建關聯節視圖的子程序。

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

HRESULT CreateSectionViewFromPlanInDrawingDoc(CATDocument *ipNewDoc, CATPlane*ipiPlane)

{

HRESULT hr = E_FAIL;

if (ipNewDoc && ipiPlane)

{

// 繪制標準創建

// ===============================

// 使用 CATIDftDocumentServices接口獲取繪圖功能

CATIDftDrawing *piDftDrawing = NULL;

CATIDftDocumentServices *piDftDocServices = NULL;

CATIContainer_var spDrwCont;

if (SUCCEEDED(ipNewDoc->QueryInterface(IID_CATIDftDocumentServices, (void **)&piDftDocServices)))

{

piDftDocServices->GetDrawing(IID_CATIDftDrawing, (void **)&piDftDrawing);

piDftDocServices->Release();

piDftDocServices = NULL;

if (piDftDrawing)

{

CATISpecObject *piDrawingSO=NULL;

if (SUCCEEDED(piDftDrawing->QueryInterface(IID_CATISpecObject,(void **)&piDrawingSO)))

{

spDrwCont = piDrawingSO->GetFeatContainer();

if (NULL_var != spDrwCont)

{

CATIDftStandardManager *piStdmgr = NULL;

hr = spDrwCont->QueryInterface(IID_CATIDftStandardManager,(void**)&piStdmgr);

if (SUCCEEDED(hr))

{

//在允許的標準列表中查找標準(即 的列表)。引用文件目錄中的 CATDrwSTD 文件)

CATIStringList *piListstd = NULL;

if ( SUCCEEDED(piStdmgr->GetAvailableStandards(&piListstd)) && piListstd )

{

unsigned int nbrstd = 0;

piListstd->Count(&nbrstd);

for (unsigned int indice = 0; indice < nbrstd; indice ++)

{

wchar_t *wstd = NULL;

if ( SUCCEEDED ( piListstd->Item ( indice, &wstd ) ) && wstd )

{

CATUnicodeString stdname;

const CATUnicodeString ISO_UncS = "ISO";

stdname.BuildFromWChar(wstd);

if ( stdname == ISO_UncS )

{

// 在文檔中導入 ISO 標準

piStdmgr->ImportStandard (wstd);

break;

}

delete[] wstd; wstd = NULL;

}

}

piListstd->Release(); piListstd=NULL;

}

piStdmgr->Release (); piStdmgr=NULL;

}

}

// 從繪圖文檔活動工作表中的 3D 草圖創建新生成視圖

CATIDftView *piDftSectionViewFrom3D = NULL;

CATIDftSheet *piDftSheet = NULL;

piDftDrawing->GetActiveSheet(&piDftSheet);

// 查看錨點定義

double ptOrigin[2] = {150.0,150.0};

CATMathVector normalSketch;

CATI2DLine_var spFirstLine;

CATIDftGenViewFactory *piDftGenViewFact = NULL;

if (piDftSheet && SUCCEEDED(piDftSheet->QueryInterface(IID_CATIDftGenViewFactory,(void **)&piDftGenViewFact)))

{

// vecPro 參數計算:

// VecPro 必須與由兩個極點定義的切割輪廓方向垂直且包含在平面中的方向。

CATIGeometricalElement *piGeomElem = NULL;

if (SUCCEEDED(ipiPlane->QueryInterface(CATIGeometricalElement::ClassId(), (void**) &piGeomElem)))

{

CATCell_var spCell;

CATBody_var spBody;

spBody = piGeomElem->GetBodyResult();

spCell = piGeomElem->GetGeometryResult();

if (NULL_var == spCell && NULL_var != spBody)

{

CATLISTP(CATCell) AllFaces;

spBody->GetAllCells(AllFaces, 2);

int FaceCount = AllFaces.Size();

for (int i = 1 ; i <= FaceCount; i++)

{

if (AllFaces[i])

{

spCell = CATCell_var(AllFaces[i]);

break;

}

}

}

CATMathPlane mathPlane;

ipiPlane->GetAxis(mathPlane);

CATMathPoint iLimitPoints[2];

double Pt1Coord[2] = {-100.0,0.0};

double Pt2Coord[2] = {100.0,0.0};

mathPlane.EvalPoint(Pt1Coord[0],Pt1Coord[1],iLimitPoints[0]);

mathPlane.EvalPoint(Pt2Coord[0],Pt2Coord[1],iLimitPoints[1]);

CATMathVector vecProfile = iLimitPoints[1] - iLimitPoints[0];

CATMathVector vecNormalToPlane;

mathPlane.GetNormal (vecNormalToPlane);

CATMathVector ProVec = vecNormalToPlane^vecProfile;

CATMathDirection vecPro;

vecPro.SetCoord(ProVec.GetX(),ProVec.GetY(),ProVec.GetZ());

// 偏移

int viewProfile = 0;

// 由平面定義的剖面視圖

CATISketch *ipi3DSketch = NULL;

// 在零件文檔中定義的平面

CATIProduct *piProduct= NULL;

hr = piDftGenViewFact->CreateStandAloneSectionView(ptOrigin, DftSectionView, vecPro,viewProfile, ipi3DSketch,spCell,spBody,iLimitPoints, piProduct,

&piDftSectionViewFrom3D);

piGeomElem->Release();piGeomElem=NULL;

}

piDftGenViewFact->Release();piDftGenViewFact=NULL;

}

piDrawingSO->Release();

piDrawingSO=NULL;

}

piDftDrawing->Release();

piDftDrawing = NULL;

}

}

}

return hr;

}

...

子程序CreateSectionViewFromPlaneInDrawingDoc使用方法創建 CATIdftGenViewFactory 接口的" CreateStandAloneSectionView "從平面創建剖面視圖。此接口由工作表實現。在創建繪圖視圖之前,必須初始化繪圖標準。

要初始化的主要參數有:

  • ptOrigin: 剖面視圖的錨點
  • DftSectionView: 節的類型
  • VecPro: VecPro 必須與由兩個極點定義的切割輪廓的方向垂直且包含在平面中的方向。Vecpro 方向通知系統將在剖面視圖中繪制哪個部件。
  • spCell 和 spBody 在"零件"文檔中描述平面。
  • iLimitPoints: 3D 點的坐標,用于定義輪廓的限制。

本示例中的其他參數是無用的。

保存文檔和退出

...

// 保存結果

// =================

if (pNewDoc)

{

CATDocumentServices::SaveAs(*pNewDoc, (char *)pfileNameOut);

CATDocumentServices::Remove (*pNewDoc);

}

//結束會話并刪除文檔

//=====================================

if (pDocPart)

CATDocumentServices::Remove (*pDocPart);

::Delete_Session("SampleSession");

本節表示保存新創建的 CATIA 文檔的常用順序。

總之

此用例顯示了:

1. 打開零件文檔

2. 檢索零件文檔中的相應草圖

3. 創建繪圖文檔,并初始化標準

4. 使用 CATIDftGenViewFactory 的" CreateStandAloneSectionView "方法從平面創建剖面視圖

5. 保存繪圖文檔。

參考

[1]

構建和啟動CAA 用例

[2]

加截文檔

總結

以上是生活随笔為你收集整理的#开发catia_CATIA工程制图二次开发之15:从平面创建剖面视图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。