CATIA CAA二次開發(fā)開發(fā)教材_第1頁
CATIA CAA二次開發(fā)開發(fā)教材_第2頁
CATIA CAA二次開發(fā)開發(fā)教材_第3頁
CATIA CAA二次開發(fā)開發(fā)教材_第4頁
CATIA CAA二次開發(fā)開發(fā)教材_第5頁
已閱讀5頁,還剩79頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1/84CATIACAA開發(fā)教材TOC\o"1-1"\t"編號標(biāo)題1,附錄標(biāo)識,1,編號標(biāo)題2,1,編號標(biāo)題3"1進入CAA開發(fā)世界 31.1CAA的應(yīng)用 31.2CAA開發(fā)流程界面介紹 31.3一個簡單的批處理程序 8基本思路: 8主函數(shù)返回值的含義: 8運行方式: 9代碼開發(fā)詳解: 9創(chuàng)建進程 9創(chuàng)建新文檔 9訪問文檔內(nèi)部結(jié)構(gòu) 10保存文檔 11從進程移除文檔 11關(guān)閉進程 111.4常用插件說明 122CAA對象模型 132.1整體架構(gòu) 132.2重點模型之零件設(shè)計 152.2.1零件的復(fù)制、剪切、粘貼。 152.2.2復(fù)制、粘貼功能的主函數(shù)介紹 242.3重點模型之曲面設(shè)計 312.3.1創(chuàng)建放樣曲面 312.3.2將曲面feature轉(zhuǎn)換為Datum(CAAGsiDatum.m) 382.3.3創(chuàng)建Body、GS、OGS(CAAGsiBodyGSAndOGS.m) 432.4重點模型之二維圖 563可視化、交互程序開發(fā) 573.1.1Workshop或Workbench的創(chuàng)建 573.1.2Addin的創(chuàng)建 633.1.3工具條、菜單的建立和顯示 663.2命令的響應(yīng) 683.2.1Command插入 683.2.2Dialog的插入 693.3窗體控件 723.4鼠標(biāo)事件交互選擇 773.5關(guān)于窗口/界面定義、命令響應(yīng)、系統(tǒng)組織的說明 824典型實例詳解 84CATIA二次開發(fā)進入CAA開發(fā)世界CAA的應(yīng)用CATIA能提供的功能,通常來說,都可以通過CAA編程實現(xiàn)。另外,還可以對CATIA系統(tǒng)功能進行擴展,完成CATIA通用模塊不能實現(xiàn)的工作。CAA開發(fā)主要有兩種模式:批處理模式和交互模式。批處理程序以磁盤上存儲的CATIA物理文件為處理對象,例如:在程序內(nèi)部打開一個二維圖文件CATDrawing,對工程圖內(nèi)的頁面和視圖等信息進行各種處理,最后在程序內(nèi)部關(guān)閉文件,結(jié)束操作;或者在程序內(nèi)部打開一個曲面文件,對文件內(nèi)的兩個曲面利用函數(shù)求交線,最后將求得的交線添加到結(jié)構(gòu)樹上,并關(guān)閉文件,結(jié)束操作。交互程序為用戶提供交互操作界面,用戶需將開發(fā)的插件加入catia標(biāo)準(zhǔn)配置,啟動catia后通過新創(chuàng)建的菜單、工具條、對話框等,為用戶提供交互手段。例如:用戶在catia的操作界面內(nèi)選擇2個零件,然后點擊命令按鈕,系統(tǒng)檢查這兩個零件是否有干涉,并彈出對話框顯示檢查結(jié)果。下面先對基本開發(fā)流程做介紹,然后對批處理方式進行示例。CAA開發(fā)流程界面介紹建立工程。建立Framework。(3)添加預(yù)定義工作區(qū),以搜索開發(fā)所需要的API資源。點擊“CAAV5Workspace”“LocatePrerequisiteWorkspace…”,添加CATIA的安裝路徑。注意此路徑為Intele_a文件夾的上層路徑。,如果要引用其他Workspace的接口(Interface),也可以在這里指定此Workspace的路徑。點擊“Add”添加,如下圖所示:(4)插入Module。設(shè)置當(dāng)前module,并加入CAAV5類。在類文件內(nèi),添加功能代碼。一個簡單的批處理程序目的:利用批處理的模式創(chuàng)建一個新的part文檔。(見工程1)基本思路:Create_Session:Createsanewsession,necessaryinabatchprogramNew:Createsanewdocumentofastandardtype("Part")SaveAs:SavesthedocumentunderanewnameRemove:RemovesthedocumentfromthesessionDelete_Session:Deletesthesession主函數(shù)返回值的含義:ReturnErrors://1-ERRORincreatingthesession2-ERRORincreatinganewdocument3-ERRORinQueryInterface4-ERRORinretrievingtherootcontainer5-ERRORinsavingthedocument6-ERRORinremovingthedocument7-ERRORindeletingthesession運行方式:mkrun-c"CAAOmbNewDocE:\\output.CATPart"代碼開發(fā)詳解:添加頭文件//ObjectModelerBaseFramework#include"CATSessionServices.h"http://Create_SessionandDelete_Session#include"CATDocumentServices.h"http://New,SaveAsandRemove#include"CATInit.h"http://GetRootContainer#include"CATDocument.h"http://QueryInterface-CATInit//Otherincludes#include<iostream.h>//Printtothescreenduringexecutionintmain(intargc,char*argv[])創(chuàng)建進程在程序開始之初,每個批處理程序都應(yīng)使用全局函數(shù)Create_Session創(chuàng)建一個進程。一個批處理程序內(nèi)有且僅有一個進程。char*sessionName="CAA2_Sample_Session";CATSession*pSession=NULL;HRESULTrc=::Create_Session(sessionName,pSession);if((FAILED(rc))||(NULL==pSession)){cout<<"ERRORincreatingsession"<<endl<<flush;return1;}創(chuàng)建新文檔采用CATDocumentServices的一個靜態(tài)方法::New來定義和初始化一個文檔,利用獲取的文檔指針pDoc可以對文檔做一系列操作。CATDocument*pDoc=NULL;rc=CATDocumentServices::New("CATPart",pDoc);if(NULL!=pDoc)cout<<"NewdocumentcreatedOK"<<endl<<flush;else{cout<<"ERRORincreatingNewdocument"<<endl<<flush;return2;}訪問文檔內(nèi)部結(jié)構(gòu)訪問或者更改文檔,需要通過CATInit::GetRootContainer方法獲取其RootContainer,然后再進行系列操作。對一個指針對象訪問某個屬性時,常用的方法基本可歸納為兩類:(一)、調(diào)用指針對象的成員函數(shù)。(二)、直接查詢指針對象的相關(guān)接口;基本格式如下:rc=pDoc->QueryInterface(IID_CATInit,(void**)&piInitOnDoc)。CATInit*piInitOnDoc=NULL;rc=pDoc->QueryInterface(IID_CATInit,(void**)&piInitOnDoc);if(FAILED(rc)){cout<<"ERRORinQueryInterfaceonCATInitfordoc"<<endl<<flush;return3;}constCATIdentidCATIContainer="CATIContainer";CATIContainer*piRootContainer=NULL;piRootContainer=(CATIContainer*)piInitOnDoc->GetRootContainer(idCATIContainer);if(NULL==piRootContainer){cout<<"ERRORinGetRootContainer"<<endl<<flush;return4;}保存文檔保存函數(shù)有兩個參數(shù),參數(shù)1代表文檔指針;參數(shù)2包含文檔保存路徑和文檔名稱。此外,如果有必要,還可以指定文檔的保存格式。rc=CATDocumentServices::SaveAs(*pDoc,argv[1]);if(SUCCEEDED(rc))cout<<"DocumentsavedOK"<<endl<<flush;else{cout<<"ERRORinsavingdocument"<<endl<<flush;return5;}從進程移除文檔當(dāng)程序里面不再對文檔進行操作時,在保證文檔已經(jīng)保存的前提下,應(yīng)將移除文檔。rc=CATDocumentServices::Remove(*pDoc);if(SUCCEEDED(rc))cout<<"DocumentremovedOK"<<endl<<flush;else{cout<<"ERRORinremovingdocument"<<endl<<flush;return6;}關(guān)閉進程開發(fā)結(jié)束時需調(diào)用全局函數(shù)Delete_Session,關(guān)閉進程。rc=::Delete_Session(sessionName);if(SUCCEEDED(rc))cout<<"SessiondeletedOK"<<endl<<flush;else{cout<<"ERRORindeletingsession"<<endl<<flush;return7;}常用插件說明分別對應(yīng):對話框、響應(yīng)命令、workbench、類、工具條。

CAA對象模型整體架構(gòu)可以對CATIA的以下方面根據(jù)需求進行二次開發(fā):MechanicalDesignMechanicalModeler&SketcherPartDesignAssemblyDesignDrafting3DFunctionalTolerancing&AnnotationStructureAerospaceSheetMetalShapeDesign&StylingMechanicalModeler&SketcherGenerativeShapeDesignProductSynthesis&KnowledgewareDMUNavigatorDMUSpaceAnalysisDMUKinematicsSimulatorProductFunctionDefinitionProductEngineeringOptimizerKnowledgeExpertAnalysisAnalysisModelerGenerativeStructuralAnalysisMachiningNCReviewPrismaticMachiningLatheMachiningSurfacicMachiningAdvancedMachiningEquipment&SystemsElectricalModelerSchematicsPlatformModelerDistributiveSystemsSpatialLayoutSystemsLayoutElectricalLibraryElectricalHarnessInstallationElectricalWireRoutingElectricalFlatteningElectricalSystemFunctionalDefinitionSystemsDiagramsStructurePreliminaryLayout

重點模型之零件設(shè)計零件的復(fù)制、剪切、粘貼。功能函數(shù)介紹程序?qū)⒔榻B如何對一個pad零件應(yīng)用復(fù)制、剪切、粘貼。有關(guān)零件處理的程序中經(jīng)常用到的一些.h在這里列舉,供開發(fā)參考://PartInterfacesFramework#include"CATIPrtProfile.h"http://neededtoaccesstheprofileattributeoftheUserPad//SketcherInterfacesFramework#include"CATISketch.h"http://neededtofindasketchinapathelement//MecModInterfacesFramework#include"CATIPrtPart.h"http://neededtocheckvalidityofpastedelement//VisualizationFramework#include"CATPathElement.h"http://neededtocheckvalidityofpastedelement//MathematicsFramework#include"CATPlane.h"http://neededtocheckvalidityofpastedelement#include"CATMathPoint.h"http://neededtodefineanchorpoint#include"CATMathDirection.h"http://neededtodefinethenormalofthefeature//ObjectSpecsModelerFramework#include"CATISpecObject.h"http://neededtomanagetheprofile#include"CATISpecAttrAccess.h" //neededtoaccessUserpadattributes#include"CATISpecAttrKey.h" //neededtoaccessUserpadattributekeys#######################include"CATLISTV_CATISpecObject.h"http://neededtomanagethesketchassociatedtotheprofile#################//ObjectModelerBaseFramework#include"CATSession.h"http://neededtomanagesession#include"CATDocument.h"http://neededtomanagetheCATPartdocument#include"CATDocumentServices.h"http://neededtocreatethedocument#include"CATSessionServices.h"http://neededtocreatethesession#include"CATInit.h"http://neededtoaccessMechanicaldesigncontainer#include"CATICatalogManager.h"http://neededtoaccessUserPadstartup#include"CATICutAndPastable.h"http://neededtoperformCut/Copy/Pasteoperation//SketcherInterfacesFramework#include"CATISketchFactory.h"http://neededtocreatesketches#include"CATI2DWFFactory.h"http://neededtodrawthesketches#include"CATISketch.h"http://neededtomanagesketches#include"CATI2DCurve.h"http://neededtodrawthelinesofthesketches#include"CATI2DPoint.h"http://neededtoaccessthepointsofthesketches//MecModInterfacesFramework#include"CATIPrtContainer.h"http://neededtomanageMechanicalDesignfeatures//PartInterfacesFramework#include"CATIPrtFactory.h"http://neededtocreateUserPadprofile#include"CATIPrtProfile.h"http://neededtovaluateUserPadattribute//ObjectSpecsModelerFramework#include"CATISpecObject.h"http://neededtoqueryinterface#include"CATISpecAttrAccess.h" //neededtoaccessUserpadattributes#include"CATISpecAttrKey.h" //neededtoaccessUserpadattributekeys#include"CATIDescendants.h"http://neededtoaggregateUserpadattribute#include"CATICatalog.h"http://neededtoaccessUserPadstartup#include"CATCatalogFactoryServices.h"http://neededtoopenStartUpcatalog//MechanicalModelerFramework#include"CATMfDefs.h"http://neededtodefinethekeysoftheproceduralreport#include"CATIPrtProceduralView.h"http://neededtoinsertUserPadfeatureintheproceduralview#include"CATIShapeFeatureProperties.h"http://neededtotestthattheuserpasisaformfeature通過接口CATIMechanicalCCP的函數(shù),可以判斷一個特征是否允許被復(fù)制、刪除、粘貼。其函數(shù)共6個:GiveMeYourFavoriteSpecificationsIsElementValidForPasteGetAnchorPointGetReferenceNormalCanBeDeletedCanBeCopied[1]返回用來創(chuàng)建pad用的特征列表。CATLISTV(CATISpecObject_var)CAAPriEMechanicalCCP::GiveMeYourFavoriteSpecifications()const{//RetrievestheProfileattributeoftheUserPadfeature.//CATLISTV(CATISpecObject_var)listSpec;CATISpecObject*piUserPad=NULL;HRESULTrc=((CATBaseUnknown*)this)->QueryInterface(IID_CATISpecObject,(void**)&piUserPad);if(FAILED(rc))returnlistSpec;CATISpecAttribute*piProfileAtt=piUserPad->GetAttribute("Profile");if(NULL!=piProfileAtt){CATISpecObject_varspProfile=piProfileAtt->GetSpecObject(1);piProfileAtt->Release();if(NULL_var!=spProfile){spProfile->Release();//Todecrementthereferencecount//Retrievesthesketchassociatedwiththeprofile//Thesketchisaddedinthereturnedlist//CATIPrtProfile_varspPrtProfileOnProfile(spProfile);if(NULL_var!=spPrtProfileOnProfile){CATISpecObject_varspElt=NULL_var;spPrtProfileOnProfile->GetElement(1,spElt);if(NULL_var!=spElt){listSpec.Append(spElt);}}}}piUserPad->Release();returnlistSpec;}[2]判斷是否允許粘貼,允許返回1,不允許返回0。intCAAPriEMechanicalCCP::IsElementValidForPaste(CATPathElement*ispPath)const{intvalid=0;//checkingifthereisasketchinthepathelement//CATBaseUnknown*spiSketchOnElt=ispPath->FindElement(IID_CATISketch);if(NULL!=spiSketchOnElt){spiSketchOnElt->Release();valid=1;}returnvalid;}[3]用來獲得被拷貝對象的絕對坐標(biāo)系CATMathPointCAAPriEMechanicalCCP::GetAnchorPoint()const{//RetrievestheProfileattributeoftheUserPadfeature.//CATMathPointanchorPoint;CATISpecObject*piUserPad=NULL;HRESULTrc=((CATBaseUnknown*)this)->QueryInterface(IID_CATISpecObject,(void**)&piUserPad);if(FAILED(rc))returnanchorPoint;CATISpecAttribute*piProfileAtt=piUserPad->GetAttribute("Profile");if(NULL!=piProfileAtt){CATISpecObject_varspProfile=piProfileAtt->GetSpecObject(1);piProfileAtt->Release();if(NULL_var!=spProfile){spProfile->Release();//Retrievesthesketchassociatedwiththeprofile//Thesketchisaddedinthereturnedlist//CATIPrtProfile_varspPrtProfileOnProfile(spProfile);if(NULL_var!=spPrtProfileOnProfile){intnbElt=spPrtProfileOnProfile->GetElementCount();if(1==nbElt){//Retrievesthesketchassociatedtotheprofile//CATISpecObject_varspElt;spPrtProfileOnProfile->GetElement(1,spElt);CATIMechanicalCCP_varspCCPOnElt(spElt);if(NULL_var!=spCCPOnElt){//DelegatesGetAnchorPointtothesketch//anchorPoint=spCCPOnElt->GetAnchorPoint();}}}}}piUserPad->Release();returnanchorPoint;}[4]獲得特征的法線CATMathDirectionCAAPriEMechanicalCCP::GetReferenceNormal()const{//RetrievestheProfileattributeoftheUserPadfeature.//CATMathDirectionnormal;CATISpecObject*piUserPad=NULL;HRESULTrc=((CATBaseUnknown*)this)->QueryInterface(IID_CATISpecObject,(void**)&piUserPad);if(FAILED(rc))returnnormal;CATISpecAttribute*piProfileAtt=piUserPad->GetAttribute("Profile");if(NULL!=piProfileAtt){CATISpecObject_varspProfile=piProfileAtt->GetSpecObject(1);piProfileAtt->Release();if(NULL_var!=spProfile){spProfile->Release();//Retrievesthesketchassociatedwiththeprofile//Thesketchisaddedinthereturnedlist//CATIPrtProfile_varspPrtProfileOnProfile(spProfile);if(NULL_var!=spPrtProfileOnProfile){intnbElt=spPrtProfileOnProfile->GetElementCount();if(1==nbElt){CATISpecObject_varspElt;spPrtProfileOnProfile->GetElement(1,spElt);CATIMechanicalCCP_varspCCPOnElt(spElt);if(spCCPOnElt!=NULL_var){//DelegatesGetReferenceNormaltothesketch//normal=spCCPOnElt->GetReferenceNormal();}}}}}piUserPad->Release();returnnormal;}[5]用來判斷一個特征是否允許被剪切,允許返回1,否則返回值為0。intCAAPriEMechanicalCCP::CanBeDeleted(CATListValCATISpecObject_varList)const{return1;}[6]用來判斷一個特征是否允許被拷貝。如果可以被拷貝,返回值為1,否則為0。 intCAAPriEMechanicalCCP::CanBeCopied()const { return1; }通過接口CATIShapeFeatureProperties的函數(shù),定義實體特征的行為。這里共使用了兩個:GetPolarityGiveMeYourFavoriteSketches復(fù)制、粘貼功能的主函數(shù)介紹程序包括:CAAPriCutCopyPast.m、CAAPriCutCopyPasteMain.m。前者包含了開發(fā)中用到的系統(tǒng)方法,后者是程序?qū)崿F(xiàn)的主函數(shù)。CAAPriCutCopyPasteMain.m包含了一個main函數(shù),首先創(chuàng)建了一個part文檔。之后執(zhí)行復(fù)制、粘貼命令。最后將結(jié)果保存在新創(chuàng)建的part文件中。創(chuàng)建進程,新建一個catpart文件。CATSession*pSampleSession=NULL;Create_Session("SampleSession",pSampleSession);CATDocument*pDoc=NULL;CATDocumentServices::New("CATPart",pDoc);對文檔初始化后,鎖定文檔,防止在執(zhí)行復(fù)制、粘貼、剪切操作時丟失數(shù)據(jù),要注意在結(jié)束程序時,必須解除對文檔的鎖定。CATInit_varspInitOnDoc(pDoc);CATLockDocument((*pDoc));獲取零件結(jié)構(gòu)樹的根結(jié)構(gòu)。CATIPrtContainer*spPrtCont=(CATIPrtContainer*)spInitOnDoc->GetRootContainer("CATIPrtContainer"); 調(diào)用SketchFactory草圖模塊,為在PartBody上創(chuàng)建草圖特征做好準(zhǔn)備。CATISketchFactory_varspSketchFactOnPrtCont(spPrtCont);獲取參考平面的鏈表。CATIPrtPart_varspPart;if(spPrtCont)spPart=spPrtCont->GetPart();CATListValCATISpecObject_varspListRefPlanes=spPart->GetReferencePlanes();將XY平面作為草圖工作平面。CATISpecObject_varspSketchPlane=spListRefPlanes[1];CATISketch_varspSketch1=spSketchFactOnPrtCont->CreateSketch(spSketchPlane);定義二維圖Factory,為創(chuàng)建二維圖元素做準(zhǔn)備。CATI2DWFFactory_varspWF2DFactOnSketch1(spSketch1);定義數(shù)組,為創(chuàng)建草圖元素做準(zhǔn)備。doublept1Sk1[2]={10.,5.},pt2Sk1[2]={-10.,5.},pt3Sk1[2]={-10.,-5.},pt4Sk1[2]={10.,-5.};激活結(jié)點,如圖中的“草圖.1”,將進入草圖編輯界面,創(chuàng)建相應(yīng)的二維圖元素。spSketch1->OpenEdition();創(chuàng)建直線。 CATISpecObject_varspLine1Sk1=spWF2DFactOnSketch1->CreateLine(pt1Sk1,pt2Sk1);CATISpecObject_varspLine2Sk1=spWF2DFactOnSketch1->CreateLine(pt2Sk1,pt3Sk1);CATISpecObject_varspLine3Sk1=spWF2DFactOnSketch1->CreateLine(pt3Sk1,pt4Sk1);CATISpecObject_varspLine4Sk1=spWF2DFactOnSketch1->CreateLine(pt4Sk1,pt1Sk1);創(chuàng)建曲線兩個端點。GetStartPoint()和GetEndPoint()可以返回點,也可以創(chuàng)建點。CATI2DCurve_varspCurveOnLine1Sk1(spLine1Sk1);spCurveOnLine1Sk1->GetStartPoint();spCurveOnLine1Sk1->GetEndPoint();CATI2DCurve_varspCurveOnLine2Sk1(spLine2Sk1);spCurveOnLine2Sk1->GetStartPoint();spCurveOnLine2Sk1->GetEndPoint();CATI2DCurve_varspCurveOnLine3Sk1(spLine3Sk1);spCurveOnLine3Sk1->GetStartPoint();spCurveOnLine3Sk1->GetEndPoint();CATI2DCurve_varspCurveOnLine4Sk1(spLine4Sk1);spCurveOnLine4Sk1->GetStartPoint();spCurveOnLine4Sk1->GetEndPoint();結(jié)束草圖編輯。spSketch1->CloseEdition(); 利用剛剛創(chuàng)建的草圖創(chuàng)建凸臺,通過Update添加到結(jié)構(gòu)樹。CATISpecObject_varspUserPad1=CreateUserPad(spPrtCont,spSketch1);spUserPad1->Update();將當(dāng)前結(jié)果保存到文檔1中。HRESULTboolSave=E_FAIL;char*nomPart1=iArgv[1];boolSave=CATDocumentServices::SaveAs(*pDoc,nomPart1);接下來創(chuàng)建第二個草圖,完成復(fù)制、剪切等功能。以YZ平面做為參考平面。CATISpecObject_varspSketchPlane2=spListRefPlanes[2];CATISketch_varspSketch2=spSketchFactOnPrtCont->CreateSketch(spSketchPlane2);CATI2DWFFactory_varspWF2DFactOnSketch2(spSketch2);doublept1Sk2[2]={15.,5.},pt2Sk2[2]={25.,5.},pt3Sk2[2]={25.,25.},pt4Sk2[2]={15.,25.};打開草圖結(jié)點,進入二維圖編輯界面,創(chuàng)建直線。spSketch2->OpenEdition();CATISpecObject_varspLine1Sk2=spWF2DFactOnSketch2->CreateLine(pt1Sk2,pt2Sk2);CATISpecObject_varspLine2Sk2=spWF2DFactOnSketch2->CreateLine(pt2Sk2,pt3Sk2);CATISpecObject_varspLine3Sk2=spWF2DFactOnSketch2->CreateLine(pt3Sk2,pt4Sk2);CATISpecObject_varspLine4Sk2=spWF2DFactOnSketch2->CreateLine(pt4Sk2,pt1Sk2);創(chuàng)建直線的兩個端點。CATI2DCurve_varspCurveOnLine1Sk2(spLine1Sk2);spCurveOnLine1Sk2->GetStartPoint();spCurveOnLine1Sk2->GetEndPoint();CATI2DCurve_varspCurveOnLine2Sk2(spLine2Sk2);spCurveOnLine2Sk2->GetStartPoint();spCurveOnLine2Sk2->GetEndPoint();CATI2DCurve_varspCurveOnLine3Sk2(spLine3Sk2);spCurveOnLine3Sk2->GetStartPoint();spCurveOnLine3Sk2->GetEndPoint();CATI2DCurve_varspCurveOnLine4Sk2(spLine4Sk2);spCurveOnLine4Sk2->GetStartPoint();spCurveOnLine4Sk2->GetEndPoint();結(jié)束草圖編輯。spSketch2->CloseEdition();檢查基于草圖1的凸臺,為執(zhí)行拷貝、粘貼做準(zhǔn)備。CATIShapeFeatureProperties*pShapeFeaturePropertiesOnUserPad1=NULL;HRESULThr=spUserPad1->QueryInterface(IID_CATIShapeFeatureProperties,(void**)&pShapeFeaturePropertiesOnUserPad1);if(SUCCEEDED(hr)){intContFeat=pShapeFeaturePropertiesOnUserPad1->IsAContextualFeature();if(1==ContFeat)return5;intFormFeat=pShapeFeaturePropertiesOnUserPad1->IsAFreeFormFeature();if(0==FormFeat)return5;pShapeFeaturePropertiesOnUserPad1->Release();pShapeFeaturePropertiesOnUserPad1=NULL;執(zhí)行拷貝功能,將基于草圖1的數(shù)據(jù),復(fù)制到草圖2上。CATICutAndPastable_varspStartCAPOnPrtCont(spPrtCont);創(chuàng)建草圖2的PathElement列表,在里面添加所需的元素。CATLISTV(CATBaseUnknown_var)listTargets;if(spSketch2!=NULL_var) {CATPathElement*pathTarget=newCATPathElement((CATISketch*)spSketch2);pathTarget->AddFatherElement(CATISpecObject_var(spSketch2)->GetFather());listTargets.Append(pathTarget);pathTarget->Release(); }將凸臺1作為拷貝源,添加到列表。CATLISTV(CATBaseUnknown_var)listObjectsToCopy;listObjectsToCopy.Append(spUserPad1);判斷對象是否可以提取特征用來執(zhí)行拷貝功能。如果有可提取的對象,返回值為1;否則為0。CATLISTV(CATBaseUnknown_var)listObjectsAlreadyInBoundary;intresultat=spStartCAPOnPrtCont->BoundaryExtract(listObjectsAlreadyInBoundary,&listObjectsToCopy,NULL);創(chuàng)建粘貼板數(shù)據(jù)。CATBaseUnknown_varspEltCopy=spStartCAPOnPrtCont->Extract(listObjectsAlreadyInBoundary,NULL);在粘貼板的源對象上,檢測可以做粘貼操作的對象列表。CATICutAndPastable_varspCAPOnEltCopy(spEltCopy);CATLISTV(CATBaseUnknown_var)listObjects;intresultat2=spCAPOnEltCopy->BoundaryExtract(listObjects,NULL,NULL);創(chuàng)建執(zhí)行拷貝功能的操作對象。CATICutAndPastable_varspEndCAPOnPrtCont(spPrtCont);將源對象拷貝到目標(biāo)對象。CATLISTV(CATBaseUnknown_var)spFinalObject=spEndCAPOnPrtCont->Paste(listObjects,&listTargets,NULL);更新結(jié)構(gòu)樹顯示。CATISpecObject_varspSpecOnPart(spPart);if(NULL_var!=spSpecOnPart)spSpecOnPart->Update();對執(zhí)行了拷貝、粘貼等操作的結(jié)果文件保存在文檔2中。boolSave=E_FAIL;char*nomPart2=iArgv[2];boolSave=CATDocumentServices::SaveAs(*pDoc,nomPart2);解鎖文檔、移除文檔、關(guān)閉進程。CATUnLockDocument((*pDoc));boolSave=CATDocumentServices::Remove(*pDoc);pDoc=NULL;boolSave=::Delete_Session("SampleSession");

重點模型之曲面設(shè)計創(chuàng)建放樣曲面程序模塊的開發(fā)目標(biāo)是創(chuàng)建下圖所示的曲面,基本步驟是:首先創(chuàng)建線框元素(Point,Plane,Circle),然后用Sweep,Loft等方法創(chuàng)建外形曲面。運行方式:程序需要指定一個參數(shù),用于保存生成曲面的part。通過程序開發(fā),掌握以下知識:(1)創(chuàng)建part文檔。(2)創(chuàng)建GSMTool并設(shè)置為當(dāng)前狀態(tài)。(3)創(chuàng)建點、線、面、圓、掃掠、放樣。(4)保存part文檔。初始化--創(chuàng)建進程、新文檔在本工程里定義了一個工具模塊CAAGsiUserTools,有關(guān)曲面設(shè)計的一些常用工具均在里面定義,使用時,只需調(diào)用工具模塊的一個對象,即可調(diào)用相應(yīng)的設(shè)計工具。程序首先檢查輸入?yún)?shù)的合法性,然后調(diào)用工具模塊的Init方法,完成:創(chuàng)建進程、創(chuàng)建新文檔兩項任務(wù)。intRetCode=0;HRESULTrc=S_OK;char*pPartName=NULL;pPartName=iArgv[1];CAAGsiUserToolsCAAGsiObjTool;char*pSessionName="CAA2SampleSession";rc=CAAGsiObjTool.Init(pSessionName);創(chuàng)建openbody&GSMTool創(chuàng)建一個openbody,用于容納新創(chuàng)建的幾何圖形,創(chuàng)建GSM工具并設(shè)置為當(dāng)前對象,用來創(chuàng)建所有的特征。CATLISTV(CATISpecObject_var)aObjectParameters;intsetAsCurrent=1;intCreationLocation=0;intTypeOfGeometricalSet=pTypeOfTool;CATIGSMTool_varspTool=CAAGsiObjTool.CreateGSMTool("Nozzle",setAsCurrent,0,TypeOfGeometricalSet);創(chuàng)建幾何特征創(chuàng)建點創(chuàng)建點的工作主要分為四步:(1)創(chuàng)建點的長度特征,分xyz三部分。(2)將創(chuàng)建的點特征依次加入特征容器(3)調(diào)用中CAAGsiObjTool創(chuàng)建點的方法,根據(jù)特征容器創(chuàng)建點。(4)清空特征容器,為下次執(zhí)行做準(zhǔn)備。 CATISpecObject_varspCurrent=NULL_var;//Point(17,0,0)CAAGsiObjTool.CreateLength("X",17.0,spCurrent);aObjectParameters.Append(spCurrent);CAAGsiObjTool.CreateLength("Y",0.0,spCurrent);aObjectParameters.Append(spCurrent);CAAGsiObjTool.CreateLength("Z",0.0,spCurrent);aObjectParameters.Append(spCurrent);CATISpecObject_varspPoint1=CAAGsiObjTool.CreatePointCoord(aObjectParameters);aObjectParameters.RemoveAll();創(chuàng)建平面創(chuàng)建plane的工作類似于創(chuàng)建點,分為4步:(1)創(chuàng)建平面特征,分ABCD4部分。(2)將創(chuàng)建的平面特征依次加入特征容器(3)調(diào)用中CAAGsiObjTool創(chuàng)建平面方程的方法,根據(jù)特征容器創(chuàng)建平面。(4)清空特征容器,為下次執(zhí)行做準(zhǔn)備。以創(chuàng)建平面Y=15為例,其參數(shù)可如下設(shè)置。//AnalyticplaneY=15CAAGsiObjTool.CreateReal("A",0.0,spCurrent);aObjectParameters.Append(spCurrent);CAAGsiObjTool.CreateReal("B",1.0,spCurrent);aObjectParameters.Append(spCurrent);CAAGsiObjTool.CreateReal("C",0.0,spCurrent);aObjectParameters.Append(spCurrent);CAAGsiObjTool.CreateLength("D",15.0,spCurrent);aObjectParameters.Append(spCurrent);CATISpecObject_varspPlaneY15=CAAGsiObjTool.CreatePlaneEquation(aObjectParameters);aObjectParameters.RemoveAll();創(chuàng)建直線創(chuàng)建直線的工作分為3步:(1)在特征容器中加入兩個點。(2)調(diào)用中CAAGsiObjTool創(chuàng)建平直線的方法,根據(jù)特征容器創(chuàng)建直線。(3)清空特征容器,為下次執(zhí)行做準(zhǔn)備。下面是在xy平面中創(chuàng)建一條直線。aObjectParameters.Append(spPoint1);aObjectParameters.Append(spPoint3); CATISpecObject_varspLine2=CAAGsiObjTool.CreateLinePtPt(aObjectParameters);aObjectParameters.RemoveAll();創(chuàng)建圓環(huán)創(chuàng)建圓環(huán)的工作分為3步:在特征容器中加入兩個點。在特征容器中加入?yún)⒖计矫?。?)創(chuàng)建半徑的長度,并加入特征容器。(3)根據(jù)特征容器中的元素創(chuàng)建圓。(4)清空特征容器,為下次執(zhí)行做準(zhǔn)備。下面是在平面Y=10中創(chuàng)建半徑為17的通過點3點4的圓。aObjectParameters.Append(spPoint3);aObjectParameters.Append(spPoint4);aObjectParameters.Append(spPlaneY10);CAAGsiObjTool.CreateLength("Radius",17.0,spCurrent);aObjectParameters.Append(spCurrent);CATISpecObject_varspCircle2=CAAGsiObjTool.CreateCircle2PointsRad(aObjectParameters,FALSE,TRUE);aObjectParameters.RemoveAll();此外還需創(chuàng)建一些圓弧用來定義導(dǎo)引路徑。通過圓心、通過點、參考平面、起始角度、結(jié)束角度創(chuàng)建圓弧的方法如下:aObjectParameters.Append(spPoint11);aObjectParameters.Append(spPoint7);aObjectParameters.Append(spPlaneXY);CAAGsiObjTool.CreateAngle("Angle1",0.0,spCurrent);aObjectParameters.Append(spCurrent);CAAGsiObjTool.CreateAngle("Angle2",-90.0,spCurrent);aObjectParameters.Append(spCurrent);CATISpecObject_varspCircle5=CAAGsiObjTool.CreateCircleCenterRad(aObjectParameters,FALSE);aObjectParameters.RemoveAll();創(chuàng)建分割(Split)創(chuàng)建分割,作為導(dǎo)引線用于限制放樣曲面的范圍。這里采用了兩條圓弧。aObjectParameters.Append(spCircle6);aObjectParameters.Append(spPlaneAngle35);CATISpecObject_varspSplit1=CAAGsiObjTool.CreateSplit(aObjectParameters,TRUE);aObjectParameters.RemoveAll();創(chuàng)建掃掠曲面采用一條導(dǎo)引線的方式創(chuàng)建掃掠曲面,利用前面定義的直線、圓弧,調(diào)用CreateSweepOneGuide方法。aObjectParameters.Append(spLine2);aObjectParameters.Append(spCircle1);CATISpecObject_varspSweep1=CAAGsiObjTool.CreateSweepOneGuide(aObjectParameters);aObjectParameters.RemoveAll();創(chuàng)建放樣曲面根據(jù)放樣曲面的定義,創(chuàng)建所需的構(gòu)造元素。首先創(chuàng)建一個樣條曲線:利用兩條直線創(chuàng)建端點的切線方向,在特征容器中加入兩個點,最后調(diào)用CreateSpline方法創(chuàng)建樣條曲線。aObjectParameters.Append(spPoint15);aObjectParameters.Append(spPoint16);CATISpecObject_varspDir1=CAAGsiObjTool.CreateDirection(spLine7);CATISpecObject_varspDir2=CAAGsiObjTool.CreateDirection(spLine8);CATISpecObject_varspSpline=CAAGsiObjTool.CreateSpline(aObjectParameters,spDir1,FALSE,spDir2,TRUE);aObjectParameters.RemoveAll();首先創(chuàng)建一個比較簡單的放樣曲面。定義兩個特征容器,分別放置截面特征、路徑特征,創(chuàng)建放樣曲面。CATLISTV(CATISpecObject_var)aObjectParametersSections;aObjectParametersSections.Append(spCircle2);aObjectParametersSections.Append(spCircle3);aObjectParameters.Append(spLine3);CATISpecObject_varspUnused=NULL_var;CATISpecObject_varspLoft1=CAAGsiObjTool.CreateLoft(aObjectParametersSections,aObjectParameters,spUnused);aObjectParameters.RemoveAll();aObjectParametersSections.RemoveAll();之后創(chuàng)建一個帶切割特征的較復(fù)雜放樣曲面。aObjectParametersSections.Append(spCircle7);aObjectParametersSections.Append(spCircle4);aObjectParameters.Append(spSplit1);aObjectParameters.Append(spSplit2);CATISpecObject_varspLoft2=CAAGsiObjTool.CreateLoft(aObjectParametersSections,aObjectParameters,spSpline);aObjectParameters.RemoveAll();aObjectParametersSections.RemoveAll();關(guān)閉進程,保存文檔調(diào)用CAAGsiObjTool中的方法,將文件保存在由輸入?yún)?shù)指定的路徑中,最后關(guān)閉進程,結(jié)束程序。rc=CAAGsiObjTool.Save(pPartName);rc=CAAGsiObjTool.Close(pSessionName);在點、線、面的特征創(chuàng)建中,多次用多了CreateAngleCreateLengthCreateReal方法,用于創(chuàng)建最基本的幾何元素,其區(qū)別是:CreateAngle:創(chuàng)建角度數(shù)值,CreateLength:創(chuàng)建長度數(shù)值。CreateReal:創(chuàng)建比例數(shù)值。將曲面feature轉(zhuǎn)換為Datum(CAAGsiDatum.m)本用例將完成以下任務(wù):讀入曲面文件、join所有曲面、將join結(jié)果轉(zhuǎn)換為Datum,Datum不包含子結(jié)構(gòu),不存在上下文結(jié)構(gòu),即它的結(jié)構(gòu)是穩(wěn)定的。程序運行時,需輸入:待處理曲面文件、保存結(jié)果文件。類似:CAAGsiDatumE:\tmp\CAAGsiNozzle.CATPartE:\tmp\CAAGsiDatum.CATPart最終的處理結(jié)果,在3D顯示區(qū)和結(jié)構(gòu)樹上如圖:載入文檔在程序里面定義一些出錯原因,供調(diào)試使用://0successfulexecution//1badnumberofarguments//2problemduringdocumentcreation//3problemduringdocumentdeletion//4problemduringPartSave創(chuàng)建進程、打開曲面文件。char*pSessionName="SampleSession";CATSession*pSession=NULL;rc=Create_Session(pSessionName,pSession);CATDocument*pDoc=NULL;rc=CATDocumentServices::OpenDocument(InputName,pDoc);CATIPrtContainer*piPartContainer=NULL;CATIPrtPart_varspPrtPart;訪問零件結(jié)構(gòu)的特征容器和幾何容器。CATInit*pDocAsInit=NULL;pDoc->QueryInterface(IID_CATInit,(void**)&pDocAsInit);piPartContainer=(CATIPrtContainer*)pDocAsInit->GetRootContainer("CATIPrtContainer");pDocAsInit->Release();pDocAsInit=NULL;if(NULL!=piPartContainer){CATISpecObject_varspPart=piPartContainer->GetPart();spPrtPart=spPart;}獲取GSM接口,為Create元素做數(shù)據(jù)準(zhǔn)備。CATIGSMFactory_varspGsmFact;if(NULL!=piPartContainer){CATIGSMFactory*_pFact=NULL;rc=piPartContainer->QueryInterface(IID_CATIGSMFactory,(void**)&_pFact);if(SUCCEEDED(rc)){spGsmFact=_pFact;if(_pFact)_pFact->Release();_pFact=NULL;}piPartContainer->Release();piPartContainer=NULL;}在當(dāng)前文檔中搜索對象,通過曲面的名稱在結(jié)構(gòu)樹上查找包含的4個曲面。CATISpecObject_varspSweep1,spSweep2,spLoft1,spLoft2;intiValidatedInput=1;if(NULL_var!=spPrtPart){CATUnicodeStringSweep1Name("Sweep.1");spSweep1=CAAGsiSearchFeatureFromName(spPrtPart,Sweep1Name);CATUnicodeStringSweep2Name("Sweep.2");spSweep2=CAAGsiSearchFeatureFromName(spPrtPart,Sweep2Name);CATUnicodeStringL

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論