CAA實(shí)用代碼片段:
/*常見編譯錯(cuò)誤:
fatal error C1189: #error :WINDOWS.H already included.
解決方法:最頂端定義預(yù)編譯的宏*/
#ifdef _WINDOWS_
#undef _WINDOWS_ #include <afx.h>
#endif
CAA常用代碼構(gòu)件
#include<afxwin.h>
AfcMessageBox(_T("hello!Point Command"));
//變量和表達(dá)式轉(zhuǎn)換成字符串
//使用字符串運(yùn)算符來實(shí)現(xiàn)轉(zhuǎn)換輸出定義
#define PR(x) cout<<#x"="<<x<<"\n";
//一、彈出對(duì)話框
//1、CATDlgNotify
CATDlgNotify _OpenNotify;
CATUnicodeString NotifyText;
//NotifyText.BuildFromNum(iInputAllocatedSize);
_OpenNotify = new CATDlgNotify(this, "TEST", CATDlgNfyWarning|CATDlgNfyOK);
_OpenNotify->SetText(NotifyText);
_OpenNotify->SetVisibility(CATDlgShow);
//2、MessageBox CATUnicodeString -->LPSTR 利用CString afxstr;
CATUnicodeString InstanceName;
spProduct->GetPrdInstanceName(InstanceName);
CString name=InstanceName.ConvertToChar();
MessageBox(NULL,name,L"OK",MB_OK | MB_SYSTEMMODAL);
MessageBox(NULL,L"Hello World!",L"成功",MB_OK | MB_SYSTEMMODAL);
//二、獲取CATIA環(huán)境變量:
CATUnicodeString oPreviewFileName,TmpDir,File;
char *slash_tmp = NULL;
if (CATGetEnvValue("CATInstallPath", &slash_tmp) == CATLibSuccess)
oPreviewFileName = slash_tmp;
if (slash_tmp) free(slash_tmp); slash_tmp=NULL;
#ifndef _WINDOWS_SOURCE
oPreviewFileName.Append("\\");
#else
oPreviewFileName.Append("/");
#endif
oPreviewFileName.Append("CAAxPDMPreview.jpg");
// get System environment variable
char *pathvar;
pathvar = getenv("PATH");
cout << pathvar << endl
/*CATIA CAA 32位和64位編譯
修改環(huán)境變量:
_MkmkOS_BitMode = 32 // Win32位編譯
_MkmkOS_BitMode = 64 // Win64位編譯
*/
//三、元素隱藏與顯示
/**
* 隱藏元素
* @param ipListElemObj
* 元素列表
*/
void HideElements(CATLISTV(CATISpecObject_var) ipListElemObj)
{
for(int i=1;i<ipListElemobj.Size();i++;)
{
CATIVisProperties* pPropONElem = NULL;
HRESULT rc = ipListElemobj[i]->QueryInterface(IID_CATIVisProperties,(void**) &pPropONElem );
if (NULL != pPropONElem)
{
CATIVisPropertiesValues PropValue;
CATIVisPropertyType PropTypeOnPtObj = CATVPShow;
CATVisGeomType GeomTypeOnPtObj = CATVPGlobalType;
PropValue.SetShowAttr(CATNOShowAttr);
rc = pPropONElem -> SetPropertiesAttr(PropValue,
PropTypeOnPtObj,
GeomTypeOnPtObj);
pPropONElem ->Release();
pPropONElem = NULL;
}
}
}
/**
* 檢測(cè)元素顯示狀態(tài)
*/
bool CheckIsShow(CATIVisProperties_var spPropOnTreeNode)
{
// 5/18 add
bool IsShow = false;
CATShowAttribut oShow ;
if ( NULL_var != spPropOnTreeNode )
{
if ( SUCCEEDED(GetShow(spPropOnTreeNode,oShow,2)))
{
// model show flag
if (oShow == CATShowAttr)
{
IsShow = true;
}
}
}//--- 5/18 add
return IsShow;
}
/**
* 取得元素顯示標(biāo)識(shí) Show Flag
*/
HRESULT GetShow(CATIVisProperties_var spProp, CATShowAttribut &oShow ,int Mode )
{
if ( spProp == NULL_var)
return E_FAIL;
CATVisPropertiesValues MyPropertyOnFace;
CATVisPropertyType PropTypeOnFace = CATVPShow;
CATVisGeomType GeomTypeOnFace;
if ( Mode == 1 )
GeomTypeOnFace = CATVPMesh;
else
GeomTypeOnFace = CATVPGlobalType ;
HRESULT rc = spProp->GetPropertiesAtt(MyPropertyOnFace,PropTypeOnFace,GeomTypeOnFace);
if ( SUCCEEDED(rc) )
{
HRESULT HR = MyPropertyOnFace.GetShowAttr(oShow);
if ( FAILED(HR))
return E_FAIL;
}
return S_OK;
}
//四、元素隱藏與顯示
/**
* 高亮特征
* @param spSpec
* 高亮特征
*/
HRESULT HighLightSpecObject (CATISpecObject_var spSpec, CATBoolean boolClearHistory)
{
HRESULT rc = E_FAIL;
CATFrmEditor * pEditor = CATFrmEditor::GetCurrentEditor();
if(NULL == pEditor )
return rc;
CATHSO * pHSO = pEditor->GetHSO();
if(NULL == pHSO )
return rc;
//為1時(shí),清楚所有已有的高亮
if(boolClearHistory)
pHSO->Empty();
CATPathElement pContext = pEditor->GetUIActiveObject();
CATIBuildPath * piBuildPath = NULL;
rc =spSpec->QueryInterface(IID_CATIBuildPath, (void **)&piBuildPath);
if(SUCCEEDED(rc) && piBuildPath != NULL)
{
CATPathElement * pPathElement = NULL;
rc = piBuildPath->ExtractPathElement(&pContext, &pPathElement);
if (pPathElement != NULL)
{
pHSO->AddElement(pPathElement);
pPathElement->Release();
pPathElement = NULL;
}
piBuildPath->Release();
piBuildPath = NULL;
}
return S_OK;
}
//五、屬性獲取
CATIAttributesDescription *piAttrDesc = NULL;
rc = spRootProduct->QueryInterface(IID_CATIAttributesDescription, (void **) &piAttrDesc);
if (FAILED(rc) || (NULL == piAttrDesc))
{
cout << "QueryInterface CATIAttributesDescription error" << endl;
return 4;
}
CATIInstance *piInstance = NULL;
rc = spRootProduct->QueryInterface(IID_CATIInstance, (void **) &piInstance);
if (FAILED(rc) || (NULL == piInstance))
{
cout << "QueryInterface CATIInstance error" << endl;
return 4;
}
CATListValCATAttributeInfos attrInfoList;
piAttrDesc->List(&attrInfoList);
for (int i = 1; i <= attrInfoList.Size(); i++)
{
CATAttributeInfos attrInfo = attrInfoList[i];
const CATUnicodeString& propertyName = attrInfo.Name(); //屬性名
const CATUnicodeString& valueType = attrInfo.Type()->Name(); //屬性類型
CATIValue *pValue = piInstance->GetValue(propertyName); //獲得對(duì)應(yīng)屬性名的屬性值
CATUnicodeString value = "";
pValue->AsString(value);
cout << propertyName << "-" << valueType << "-" << value << endl;
if (pValue)
{
pValue->Release();
pValue = NULL;
}
}
//六、CATSystemInfo 主機(jī)信息獲取
/*全局方法CATGetSystemInfo,獲得一個(gè)CATSystemInfo結(jié)構(gòu)體,包含主機(jī)名字、主機(jī)系統(tǒng)名字、系統(tǒng)版本等主機(jī)信息。*/
CATSystemInfo host;
::CATGetSystemInfo(&host);
cout << "HostName:" << host.HostName << endl;
cout << "OSName:" << host.OSName << endl;
cout << "OSVersion:" << host.OSVersion << endl;
cout << "OSType:" << host.OSType << endl;
cout << "MinorVersion:" << host.MinorVersion << endl;
cout << "MajorVersion:" << host.MajorVersion << endl;
CATTime
CATTime timeNow = CATTime::GetCurrentLocalTime();
CATUnicodeString timeStr = timeNow.ConvertToString("%Y/%m/%d-%H:%M:%S");
std::cout << "Current Time:" << timeStr.ConvertToChar() << std::endl;
//七、C# C++ 字符集轉(zhuǎn)換 字節(jié)流
string str="客服端是用c#寫的,服務(wù)端是c++";
send(str);
public void send(msg)
{
string hexstr=StringToHexString(str)
char[] chars= hexstr.ToCharArray();
byte[] byteData = Encoding.Default.GetBytes(chars);
socket.write(byteData ,0,byteData.length);
}
//字符串轉(zhuǎn)為16進(jìn)制
public string StringToHexString(string message)
{
//按照指定編碼將string編程字節(jié)數(shù)組
byte[] b = Encoding.UTF8.GetBytes(message);
string result = string.Empty;
for (int i = 0; i < b.Length; i++)
{
result += Convert.ToString(b[i], 16);
}
return result.ToUpper();
}
//八、調(diào)用exe文件
ShellExecute(0,(LPCWSTR)L"open",(LPCWSTR)L"D:\\Bin_x64\\SuperMapDemo.exe",(LPCWSTR)L"",(LPCWSTR)L"",SW_SHOWNORMAL);
SHELLEXECUTEINFO ShellInfo;
memset(&ShellInfo,0,sizeof(ShellInfo));
ShellInfo.cbSize=sizeof(ShellInfo);
ShellInfo.hwnd=NULL;
ShellInfo.lpVerb=_T("open");
//ShellInfo.lpFile=_T("..\\..\\..\\SuperMapDemo\\SuperMapDemo.exe");
ShellInfo.lpFile=_T("E:\\supermap\\Bin_x64\\SuperMapDemo.exe");
ShellInfo.lpParameters= name;
ShellInfo.nShow=SW_HIDE;//SW_SHOWNORMAL
ShellInfo.fMask=SEE_MASK_NOCLOSEPROCESS;
BOOL bResult=ShellExecuteEx(&ShellInfo);
if (!bResult)
{
return false;
}
行號(hào) 參數(shù) 含義
1 SW_HIDE 隱藏這個(gè)窗體,并激活其他窗體。
2 SW_MAXIMIZE 最大化指定的窗體。
3 SW_MINIMIZE 最小化指定的窗體,并按順序激活最上層的窗體。
4 SW_RESTORE 激活并顯示窗體。如果窗體為最小化或者最大化,窗體恢復(fù)到原始大小和位置。應(yīng)用程序當(dāng)恢復(fù)一個(gè)最小化的窗體時(shí)將指定標(biāo)記。
5 SW_SHOW 以當(dāng)前的大小和位置激活并顯示窗體。
6 SW_SHOWDEFAULT
7 SW_SHOWMAXIMIZED 激活并最大化顯示窗體。
8 SW_SHOWMINIMIZED 激活并最小化現(xiàn)實(shí)窗體。
9 SW_SHOWMINNOACTIVE 最小化窗體,保持其激活狀態(tài)。
10 SW_SHOWNA 以當(dāng)前狀態(tài)顯示窗體,保持其激活狀態(tài)。
11 SW_SHOWNOACTIVATE 以當(dāng)前的大小和位置顯示窗體,并保持其激活狀態(tài)。
12 SW_SHOWNORMAL 激活并顯示一個(gè)窗體。如果窗體為最大化或者最小化,窗體恢復(fù)到原始的大小和位置。當(dāng)窗體第一次顯示的時(shí)候,應(yīng)用程序記錄標(biāo)記。
//九、批處理模式獲得文件的rootProduct
HRESULT GetCurrentDoc_TopProduct( CATIProduct_var & spTopProd)
{
//--------------------------------------------------------------------
// 1. Prologue
//--------------------------------------------------------------------
cout << endl << flush;
cout << endl << flush;
cout << "----------------------------------------------------------------" << endl << flush;
cout << endl << flush;
// --- Creating the Session: A session must always be created in a batch
char *sessionName = "CAA_EhiFilter_Session";
CATSession *pSession = NULL;
HRESULT rc = ::Create_Session(sessionName,pSession);
if ((SUCCEEDED(rc)) && (NULL != pSession))
{
cout << "> session created : " << sessionName <<endl << flush;
}
else
{
cout << "ERROR in creating session" << sessionName << endl << flush;
return 1;
}
// --- Opening an existing document
// The input parameter to this sample program must contain
// the entire path and name of the document that is to be opened.
CATDocument *pDoc = NULL; // pDoc is a pointer to the document
cout << "> open document :"<< argv[1] << argv[2] << endl << flush;
rc = CATDocumentServices::OpenDocument(CATUnicodeString(argv[1])+CATUnicodeString(argv[2]), pDoc);
CATLockDocument(*pDoc);
if (SUCCEEDED(rc) && (NULL != pDoc))
{
cout << "> document opened " << endl << flush;
}
else
{
cout << "ERROR in opening document" << endl << flush;
return 2;
}
// --- Retrieving root product of the opened document
CATIProduct* piRootProduct = NULL; // piRootProduct is a handle to document root product
//
CATIDocRoots * piDocRoots = NULL;
rc = pDoc->QueryInterface(IID_CATIDocRoots,(void**) &piDocRoots);
if ( FAILED(rc) || (NULL==piDocRoots) )
{
cout << "ERROR : Failed to query CATIDocRoots" << endl;
return 3;
}
CATListValCATBaseUnknown_var* pListRootProduct = piDocRoots->GiveDocRoots();
piDocRoots->Release();
piDocRoots=NULL;
if ( pListRootProduct && pListRootProduct->Size() )
{
CATBaseUnknown_var hUnk = (*pListRootProduct)[1];
if (NULL_var != hUnk)
rc = hUnk->QueryInterface(IID_CATIProduct,(void**) &piRootProduct );
if (pListRootProduct)
delete pListRootProduct;
pListRootProduct = NULL;
//
if (SUCCEEDED(rc) && (NULL != piRootProduct))
{
cout << "> root product found in document " << endl << flush;
spTopProd = piProductOnRoot;
CATUnicodeString partNumber = piProductOnRoot->GetPartNumber();
cout << "Working with '" << partNumber.ConvertToChar() << "'" << endl;
return S_OK;
}
else
{
cout << "ERROR : Root product not found in document " << endl << flush;
return 3;
}
}
//--------------------------------------------------------------------
//創(chuàng)建草圖
CATInit *piInitOnDoc = NULL;
rc = pDoc -> QueryInterface (IID_CATInit,(void**) &piInitOnDoc);
if(SUCCEEDED(rc) && NULL != piInitOnDoc)
{
//獲取Container
const CATIdent idCATIContainer = "CATIPrtContainer";
CATIPrtContainer *piRootContainer = NULL;
piRootContainer = (CATIPrtContainer*)
piInitOnDoc -> GetRootContainer(idCATIContainer);
if(NULL != piRootContainer)
{
CATIPrtPart_var spPart = piRootContainer->GetPart();
CATIBasicTool_var spTool= spPart->GetCurrentTool();
CATIDescendants_var spDesTool = spPart;
CATListValCATISpecObject_var oLst ;
spDesTool->GetAllChildren("CATIMechanicalTool",oLst);
CATISpecObject_var spMainBody = oLst[1];
CATIAlias_var spAlias = spMainBody;
cout << spAlias->GetAlias() << endl << flush;
CATISketchFactory_var spSketchFactory(piRootContainer);
if(NULL_var != spSketchFactory)
{
CATISpecObject_var spSketchSpec=spSketchFactory->CreateSketch();
CATISketch_var spSketch=spSketchSpec;
if(NULL_var != spSketch)
{
spSketch->OpenEdition();
CATI2DWFFactory_var sketch2DFactory(spSketch);
if(NULL_var != sketch2DFactory)
{
double Origin[2]={0.,0.};
double Radius=10;
CATISpecObject_var spSpecCircle=
sketch2DFactory->CreateCircle(Origin,Radius);
if(NULL_var != spSpecCircle)
{
cout<<"草圖中創(chuàng)建圓成功!"<<endl;
}
spSketch->CloseEdition();
spPart->SetCurrentFeature(spMainBody);
//創(chuàng)建凸臺(tái)
CATIPrtFactory * piPrtFact=NULL;
rc=piRootContainer->QueryInterface(IID_CATIPrtFactory,
(void **)&piPrtFact);
if(SUCCEEDED(rc) && NULL != piPrtFact)
{
CATISpecObject_var spPad=piPrtFact->CreatePad(spSketch);
if(NULL_var != spPad)
{
CATIPad_var spPadPad=spPad;
if(NULL_var != spPadPad)
{
spPadPad->ModifyEndType(catOffsetLimit);
spPadPad->ModifyEndOffset(20.);
}
spPad->Update();
cout<<"創(chuàng)建凸臺(tái)成功!"<<endl;
}
piPrtFact->Release();
piPrtFact=NULL;
CATISpecObject_var spPart = piRootContainer->GetPart();
spPart->Update();
}
}
}
}
CATISpecObject_var spParentForTool = spMainBody;
CATIMechanicalRootFactory_var spMechRoot = piRootContainer;
CATISpecObject_var spSpecGS1 = NULL_var;
rc = spMechRoot -> CreateGeometricalSet("新增幾何圖形集1",spParentForTool,spSpecGS1);
}
piInitOnDoc->Release();
piInitOnDoc=NULL;
}
CAA獲取屬性
CAAProductStructure.edu
CAAPstAllProperties.m
CAAPstPrdProperties.m
/**
* Defines the relative orientation of an element with regards to another one.
* @param CATOrientationNegative
* Their orientation are opposite.
* @param CATOrientationPositive
* They have the same orientation.
* @param CATOrientationUnknown
* The orientation is not known.
*/
#define CATOrientation short
/** @nodoc */
#define CATOrientationNegative -1
/** @nodoc */
#define CATOrientationPositive 1
/** @nodoc */
#define CATOrientationUnknown 2
/**
* Defines the side where is the matter when walking along an element in the
* direction of its default orientation.
* @param CATSideLeft
* The matter is on the left.
* @param CATSideFull
* The matter is on both sides: the object is immersed inside a cell of higher dimension.
* (non manifold configuration).
* @param CATSideRight
* The matter is on the right.
* @param CATSideUnknown
* The matter side is not known.
*/
#define CATSide short
/** @nodoc */
#define CATSideLeft 1
/** @nodoc */
#define CATSideFull 0
/** @nodoc */
#define CATSideRight -1
/** @nodoc */
#define CATSideUnknown 2
E:\CATIA_developing\CAAxPDMTst\CAAxPDMInterfaces.edu\CAAxPDMReadItemInfo.m;
CATRep pRep;
CATGraphicAttributeSet ga = pRep->GetGraphicAttributeSet( ) ;
CATGraphicAttributeSet;
Role: This class permits to have a graphic attribute which define the display properties of an element.
Always associated to a rep or a graphic primitive.
C:\CATIA_V5_B22\CATMatInterfaces
C:\CATIA_V5_B22\Material
CATGraphicMaterial.h
CATIAMaterialManager GetMaterialOnPart
CATIARenderingMaterial.h
/**
* Interface for materials.
* <b>Role</b>:
* This is the base interface for materials.
* It is used to access the data needed for rendering.
*/
class CATIRdgMaterial
CATMappingOperator ComputeTextureCoordinates
Mapping operator used to calculate texture coordinates.
/** Computes the texture coordinates for all vertices.
* @param iVertex
* Array containing the coordinates of every vertices,as a succession
* of (x,y,z) sets.
* @param iNbVertex
* Number of vertices in <tt>iVertex</tt>.
* @param iNormals
* Array containing the coordinates of the normals at every vertices, as
* a succession of (Nx,Ny,Nz) sets.
* If the surface is plane, the only given set is valid for all vertices.
* @param iNormals
* Number of normal sets in <tt>iNormals</tt>.
* @param iTuv
* Array containing the parameters in of every vertices in the surface parametrization space,
* as a succession of (u,v) sets.
* This array must be required by the mapping operator through the method <tt>NeedUVMesh</tt>.
* @param iNbuv
* Number of parameter sets in <tt>iNbuv</tt>.
* @param oTexture
* Array containing the coordinates of texture coordinates for every vertices,
* as a succession of (s,t,0) sets. <br>
* (0,0,0) always indicates the lower-left corner of the texture image. <br>
* (1,1,0) always indicates the upper-right corner of the texture image.
*/
virtual void ComputeTextureCoordinates(const float iVertex[],
const int iNbVertex,
const float iNormals[],
const int iNbNormals,
const float iTuv[],
const int iNbuv,
float oTexture[]) const;